Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-WordNet NLTK关键字错误_Python_Nltk_Wordnet_Keyerror - Fatal编程技术网

Python-WordNet NLTK关键字错误

Python-WordNet NLTK关键字错误,python,nltk,wordnet,keyerror,Python,Nltk,Wordnet,Keyerror,我真的不明白。我正在使用WordNet,我遇到了麻烦。我使用如下字符串调用以下方法: F2F-流程已启动,创建计划数据,创建货物收据,创建货物收据 def lemmatise(word, pos=NOUN): return WordNetLemmatizer().lemmatize(word, pos) 这个调用下一个方法: def lemmatize(self, word, pos=NOUN): lemmas = wordnet._morphy(word, pos)

我真的不明白。我正在使用WordNet,我遇到了麻烦。我使用如下字符串调用以下方法:

F2F-流程已启动,创建计划数据,创建货物收据,创建货物收据

def lemmatise(word, pos=NOUN):
        return WordNetLemmatizer().lemmatize(word, pos)
这个调用下一个方法:

def lemmatize(self, word, pos=NOUN):
    lemmas = wordnet._morphy(word, pos)
    return min(lemmas, key=len) if lemmas else word
方法morphy()是错误的来源(请参阅错误消息)

错误消息

[18/Nov/2016 15:02:57] "GET / HTTP/1.1" 200 4364
[18/Nov/2016 15:02:57] "GET /static/website/js/animation.js HTTP/1.1" 200 180
[18/Nov/2016 15:02:57] "GET /static/website/css/animation.css HTTP/1.1" 200 1069
[18/Nov/2016 15:02:57] "GET /static/website/img/mamegra_pro_thumbnail.png HTTP/1.1" 200 3588
[18/Nov/2016 15:02:57] "GET /static/website/css/bootstrap.min.css HTTP/1.1" 200 121260
[18/Nov/2016 15:02:59] "GET /syntactic_matching_final/ HTTP/1.1" 200 5571
[18/Nov/2016 15:03:02] "GET /semantic_matching_final/ HTTP/1.1" 200 5571
Internal Server Error: /semantic_matching_final/
Traceback (most recent call last):
  File "C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\handlers\exception.py", line 39, in inner
    response = get_response(request)
  File "C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\handlers\base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Bebop\OneDrive\Masterarbeit\MamegraPro\MamegraProApp\views.py", line 418, in semantic_matching_final
    matches = matching.match_optimization('semantic_final', enable_infocontent) #perform syntactic matching and save matches in variable
  File "C:\Users\Bebop\OneDrive\Masterarbeit\MamegraPro\MamegraProApp\classes\class_matching.py", line 55, in match_optimization
    scores = {(n1, n2): self.semantic_score_final(n1.name, n2.name, enable_infocontent) if self.semantic_score_final(n1.name, n2.name, enable_infocontent) >= self.minimum_ratio else 0 for n1 in nodes1 for n2 in nodes2}
  File "C:\Users\Bebop\OneDrive\Masterarbeit\MamegraPro\MamegraProApp\classes\class_matching.py", line 55, in <dictcomp>
    scores = {(n1, n2): self.semantic_score_final(n1.name, n2.name, enable_infocontent) if self.semantic_score_final(n1.name, n2.name, enable_infocontent) >= self.minimum_ratio else 0 for n1 in nodes1 for n2 in nodes2}
  File "C:\Users\Bebop\OneDrive\Masterarbeit\MamegraPro\MamegraProApp\classes\class_matching.py", line 557, in semantic_score_final
    lemmas = self.corpusBase.lemmatise(w1)
  File "C:\Users\Bebop\OneDrive\Masterarbeit\MamegraPro\MamegraProApp\classes\class_wordnetWrapper.py", line 8, in lemmatise
    return WordNetLemmatizer().lemmatize(word, pos)
  File "C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\stem\wordnet.py", line 40, in lemmatize
    lemmas = wordnet._morphy(word, pos)
  File "C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\corpus\reader\wordnet.py", line 1687, in _morphy
    exceptions = self._exception_map[pos]
KeyError: 'Created'
[18/Nov/2016 15:03:11] "POST /semantic_matching_final/ HTTP/1.1" 500 122256
Not Found: /favicon.ico
[18/Nov/2016 15:03:12] "GET /favicon.ico HTTP/1.1" 404 4238
[18/Nov/2016 15:02:57]“GET/HTTP/1.1”200 4364
[18/Nov/2016 15:02:57]“GET/static/website/js/animation.js HTTP/1.1”200 180
[18/Nov/2016 15:02:57]“GET/static/website/css/animation.css HTTP/1.1”200 1069
[18/Nov/2016 15:02:57]“GET/static/website/img/mamegra_pro_缩略图HTTP/1.1”200 3588
[18/Nov/2016 15:02:57]“GET/static/website/css/bootstrap.min.css HTTP/1.1”200 121260
[18/Nov/2016 15:02:59]“GET/syntatic\u matching\u final/HTTP/1.1”200 5571
[18/Nov/2016 15:03:02]“GET/semantic\u matching\u final/HTTP/1.1”200 5571
内部服务器错误:/semantic\u matching\u final/
回溯(最近一次呼叫最后一次):
文件“C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site packages\django\core\handlers\exception.py”,第39行,在内部
响应=获取响应(请求)
文件“C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site packages\django\core\handlers\base.py”,第249行,在“legacy\u get\u response”中
响应=自我。获取响应(请求)
文件“C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site packages\django\core\handlers\base.py”,第187行,在get响应中
response=self.process\u异常\u由\u中间件(e,请求)
文件“C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site packages\django\core\handlers\base.py”,第185行,在get响应中
响应=包装的回调(请求,*回调参数,**回调参数)
文件“C:\Users\Bebop\OneDrive\Masterarbeit\MamegraPro\MamegraProApp\views.py”,第418行,语义匹配
matches=matching.match_优化('semantic_final',enable_infocontent)#执行语法匹配并将匹配保存在变量中
文件“C:\Users\Bebop\OneDrive\Masterarbeit\MamegraPro\MamegraProApp\classes\class\u matching.py”,第55行,匹配优化
分数={(n1,n2):self.semantic_分数_final(n1.name,n2.name,enable_infocontent)如果self.semantic_分数_final(n1.name,n2.name,enable_infocontent)>=self.minimum_ratio其他0表示节点1中的n1表示节点2中的n2}
文件“C:\Users\Bebop\OneDrive\Masterarbeit\MamegraPro\MamegraProApp\classes\class\u matching.py”,第55行,在
分数={(n1,n2):self.semantic_分数_final(n1.name,n2.name,enable_infocontent)如果self.semantic_分数_final(n1.name,n2.name,enable_infocontent)>=self.minimum_ratio其他0表示节点1中的n1表示节点2中的n2}
文件“C:\Users\Bebop\OneDrive\Masterarbeit\MamegraPro\MamegraProApp\classes\class\u matching.py”,第557行,在semantic\u score\u final中
引理=self.corpusBase.lemmasise(w1)
文件“C:\Users\Bebop\OneDrive\Masterarbeit\MamegraPro\MamegraProApp\classes\class\u wordnetWrapper.py”,lemmatise中的第8行
返回WordNetLemmatizer().lemmatize(word,pos)
文件“C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site packages\nltk\stem\wordnet.py”,第40行,在lemmatize中
引理=wordnet.\u词形(单词,词性)
文件“C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site packages\nltk\corpus\reader\wordnet.py”,第1687行,在
异常=自身。异常映射[pos]
KeyError:“已创建”
[18/Nov/2016 15:03:11]“POST/semantic\u matching\u final/HTTP/1.1”500 122256
未找到:/favicon.ico
[18/Nov/2016 15:03:12]“GET/favicon.ico HTTP/1.1”404 4238

奇怪的是,即使输入相同,它也会在抛出错误的地方随机切换单词。请帮帮我

检查以确保传递的是一个字母,而不是更长的字符串。这些可以在源nltk.corpus.reader.wordnet的常量部分找到
{词性常数ADJ,ADJ#u SAT,ADV,名词,动词='a','s','r','n','v'#}

这并没有帮助我解决这个问题,但由于你的帮助,我发现了主要问题。非常感谢。
[18/Nov/2016 15:02:57] "GET / HTTP/1.1" 200 4364
[18/Nov/2016 15:02:57] "GET /static/website/js/animation.js HTTP/1.1" 200 180
[18/Nov/2016 15:02:57] "GET /static/website/css/animation.css HTTP/1.1" 200 1069
[18/Nov/2016 15:02:57] "GET /static/website/img/mamegra_pro_thumbnail.png HTTP/1.1" 200 3588
[18/Nov/2016 15:02:57] "GET /static/website/css/bootstrap.min.css HTTP/1.1" 200 121260
[18/Nov/2016 15:02:59] "GET /syntactic_matching_final/ HTTP/1.1" 200 5571
[18/Nov/2016 15:03:02] "GET /semantic_matching_final/ HTTP/1.1" 200 5571
Internal Server Error: /semantic_matching_final/
Traceback (most recent call last):
  File "C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\handlers\exception.py", line 39, in inner
    response = get_response(request)
  File "C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\handlers\base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Bebop\OneDrive\Masterarbeit\MamegraPro\MamegraProApp\views.py", line 418, in semantic_matching_final
    matches = matching.match_optimization('semantic_final', enable_infocontent) #perform syntactic matching and save matches in variable
  File "C:\Users\Bebop\OneDrive\Masterarbeit\MamegraPro\MamegraProApp\classes\class_matching.py", line 55, in match_optimization
    scores = {(n1, n2): self.semantic_score_final(n1.name, n2.name, enable_infocontent) if self.semantic_score_final(n1.name, n2.name, enable_infocontent) >= self.minimum_ratio else 0 for n1 in nodes1 for n2 in nodes2}
  File "C:\Users\Bebop\OneDrive\Masterarbeit\MamegraPro\MamegraProApp\classes\class_matching.py", line 55, in <dictcomp>
    scores = {(n1, n2): self.semantic_score_final(n1.name, n2.name, enable_infocontent) if self.semantic_score_final(n1.name, n2.name, enable_infocontent) >= self.minimum_ratio else 0 for n1 in nodes1 for n2 in nodes2}
  File "C:\Users\Bebop\OneDrive\Masterarbeit\MamegraPro\MamegraProApp\classes\class_matching.py", line 557, in semantic_score_final
    lemmas = self.corpusBase.lemmatise(w1)
  File "C:\Users\Bebop\OneDrive\Masterarbeit\MamegraPro\MamegraProApp\classes\class_wordnetWrapper.py", line 8, in lemmatise
    return WordNetLemmatizer().lemmatize(word, pos)
  File "C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\stem\wordnet.py", line 40, in lemmatize
    lemmas = wordnet._morphy(word, pos)
  File "C:\Users\Bebop\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\corpus\reader\wordnet.py", line 1687, in _morphy
    exceptions = self._exception_map[pos]
KeyError: 'Created'
[18/Nov/2016 15:03:11] "POST /semantic_matching_final/ HTTP/1.1" 500 122256
Not Found: /favicon.ico
[18/Nov/2016 15:03:12] "GET /favicon.ico HTTP/1.1" 404 4238