2017-01-06 13 views
0

私は実際にそれを取得しません。私はWordNetを使用しており、困っています。私はそのような文字列で次のメソッドを呼び出します。Python - WordNet NLTK KeyError

F2F - プロセスが計画データを作成し、開始し、入庫を作成し、入庫が

def lemmatise(word, pos=NOUN): 
     return WordNetLemmatizer().lemmatize(word, pos) 

を作成し、この1は、次のメソッドを呼び出します:

def lemmatize(self, word, pos=NOUN): 
    lemmas = wordnet._morphy(word, pos) 
    return min(lemmas, key=len) if lemmas else word 

そして、morphy()メソッドは、エラーが原因で問題が発生したことを示します(エラーメッセージを参照)。

def _morphy(self, form, pos): 
    # from jordanbg: 
    # Given an original string x 
    # 1. Apply rules once to the input to get y1, y2, y3, etc. 
    # 2. Return all that are in the database 
    # 3. If there are no matches, keep applying rules until you either 
    # find a match or you can't go any further 
L1687 exceptions = self._exception_map[pos] 
     substitutions = self.MORPHOLOGICAL_SUBSTITUTIONS[pos] 

エラーメッセージ

[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 

奇妙なことは、それがランダムに、それも同じ入力でエラーをスロー単語を切り替えていることです。私を助けてください!

答えて

1

長い文字列ではなく1文字で渡すことを確認してください。これらは、ソースnltk.corpus.reader.wordnetの定数セクションにあります。 {品詞定数ADJ、ADJ_SAT、ADV、NOUN、VERB = 'a'、 's'、 'r'、 'n' 'v'#}

+0

これは私がこの問題を解決するのに役立たなかったが、あなたの助けのために何が大きな問題であるかを考え出した。ありがとうございました! – Bebop