Get synonyms from synset returns error - Python

后端 未结 2 1728
执笔经年
执笔经年 2021-02-11 03:19

I\'m trying to get synonyms of a given word using Wordnet. The problem is that despite I\'m doing the same as is written here: here, it returns error.

Here is my code:<

相关标签:
2条回答
  • 2021-02-11 04:08

    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())
    
    0 讨论(0)
  • 2021-02-11 04:10

    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()

    0 讨论(0)
提交回复
热议问题