Get synonyms from synset returns error - Python

早过忘川 提交于 2019-12-03 08:59:07

Which version of nltk are you using (try print nltk.__version)? Are you using python 2 or python 3? It seems that in the version you are using, lemma_names is a method and not an attribute (this is the case in nltk 3.0 for Python 3). If this is the case then you can probably fix your code by using this instead:

for i,j in enumerate(wn.synsets('small')):
    print "Synonyms:", ", ".join(j.lemma_names())

In Python 2 & 3 versions lemmas and lemma_names don't work as they are methods. You have to use lemmas() and lemma_names() instead.

For eg -

dog = wn.synset('dog.n.01') print dog.lemma_names()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!