如何以CLI的方式从NLTK Wordnet接口获取所有synonims

时间:2017-08-30 06:39:41

标签: python nltk wordnet

我正在尝试使用以下代码获取单词arbitrary的同义词:

from nltk.corpus import wordnet as wn

for i, j in enumerate(wn.synsets('arbitrary')):
    print("Meaning", i, "NLTK ID:", j.name())
    print("Definition:", j.definition())
    print("Synonyms:", ", ".join(j.lemma_names()))

结果如下:

Meaning 0 NLTK ID: arbitrary.a.01
Definition: based on or subject to individual discretion or preference or sometimes impulse or caprice
Synonyms: arbitrary

但是,当我使用CLI时,我得到了

$ wn arbitrary -synsa                                                                                                                                              

Similarity of adj arbitrary

1 sense of arbitrary                                                    

Sense 1
arbitrary (vs. nonarbitrary)
       => absolute
       => capricious, impulsive, whimsical
       => discretionary, discretional

如您所见,CLI显示更多同义词。

我尝试将WNSEARCHDIR env变量设置为NLTK corpora目录,因此CLI工具使用相同的字典NLTK。

0 个答案:

没有答案