前提・実現したいこと
シソーラスを使って単語を抽象的に変換しようとしています。
変換前: ヨーグルト を 食べる。 変換後: 乳製品 を 食べる。
発生している問題・エラーメッセージ
参考記事の通りにlemma.pyのコードをwn.pyと同じディレクトリで
実行したところ、以下のエラーが出て、このデバッグ方法がわかりません。
$ python lemma.py ヨーグルト Traceback (most recent call last): File "lemma.py", line 18, in <module> for abst_word in abstract_word(lemma=lemma): File "lemma.py", line 5, in abstract_word for word in wn.getWords(lemma): File "/Users/username/anaconda/lib/python3.6/site-packages/nltk/corpus/util.py", line 119, in __getattr__ return getattr(self, attr) AttributeError: 'WordNetCorpusReader' object has no attribute 'getWords'
該当のソースコード
日本語WordNetを使うのは以下のコードを使うとすごく楽。すごい。と参考記事で説明されていたコード(abstract_record_loader.py、sense_loader.py、synlink_loader.py、
synset_loader.py、wn.py、word_loader.py)と同じディレクトリで実行しています。
lemma.py
python
1from nltk.corpus import wordnet as wn 2 3def abstract_word(lemma): 4 result = [] 5 for word in wn.getWords(lemma): 6 for sense in wn.getSenses(word): 7 if sense.src != 'hand': continue 8 for synlink in wn.getSynLinks(sense, 'hype'): 9 abst_sense = wn.getSense(synlink.synset2) 10 if abst_sense and word.wordid != abst_sense.wordid: 11 result.append(wn.getWord(abst_sense.wordid).lemma) 12 return result 13 14 15lemma = u"ヨーグルト" 16print (lemma) 17 18for abst_word in abstract_word(lemma=lemma): 19 print ('-', abst_word)
試したこと
日本語WordNetを使うのは以下のコードを使うとすごく楽。すごい。で説明されていた方法ではうまくいきましたが、該当のソースコードではエラーが出て困っています。
$ python wn.py ヨーグルト hype ヨーグルト yoghurt 乳製品 dairy_product 食料品 foodstuff 滋養分 food 物質 substance 物質 matter 食べ物 food 固体 solid 物質 matter
補足情報(FW/ツールのバージョンなど)
python 3.6
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/05 08:49