2016-04-14 7 views
0

私はthesarusとしてWordnetを使用しようとしているので、私は単語のリストを持っており、すべての単語の同義語を収集する必要があります。私はこのwordnetの単語の同義語を見つける

from nltk.corpus import wordnet as wn 
for i,j in enumerate(wn.synsets('dog')): 
    print (j.lemma_names) 

このコードは次のような出力

<bound method Synset.lemma_names of Synset('dog.n.01')> 
<bound method Synset.lemma_names of Synset('frump.n.01')> 
<bound method Synset.lemma_names of Synset('dog.n.03')> 
<bound method Synset.lemma_names of Synset('cad.n.01')> 
<bound method Synset.lemma_names of Synset('frank.n.02')> 
<bound method Synset.lemma_names of Synset('pawl.n.01')> 
<bound method Synset.lemma_names of Synset('andiron.n.01')> 
<bound method Synset.lemma_names of Synset('chase.v.01')> 

を与えるしかし、私は唯一の同義語リストに収集したいしようとしたため、出力はこの

[「ニューサンス」のようになります

+0

最後の行 'print(j.lemma_names)'を 'print(j.lemma_names())'に変更するとどうなりますか? – davedwards

答えて

0

出力が示すように、lemma_namesはプロパティではなくメソッドです。フェラコードは、あなたが期待どおりに動作:

from nltk.corpus import wordnet as wn 
result = [st.lemma_names()[0] for st in wn.synsets('dog')] 
print(result) 

出力は次のようになります。

[u'dog', u'frump', u'dog', u'cad', u'frank', u'pawl', u'andiron', u'chase'] 

リスト内の項目は、Unicode文字列であることに注意してください。このため、出力にuの先頭が表示されます。

関連する問題