【发布时间】:2016-04-14 21:06:16
【问题描述】:
我尝试将 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')>
但我只想在列表中收集同义词,所以输出会是这样的
['frump', 'cad', 'frank', 'pawl', 'andiron', 'chase']
【问题讨论】:
-
如果将最后一行
print (j.lemma_names)更改为print (j.lemma_names())会发生什么?
标签: python python-2.7 python-3.x wordnet