Extract Word from Synset using Wordnet in NLTK 3.0

前端 未结 3 1486
梦如初夏
梦如初夏 2020-11-30 10:11

Some time ago, someone on SO asked how to retrieve a list of words for a given synset using NLTK\'s wordnet wrapper. Here is one of the suggested responses:

         


        
3条回答
  •  天涯浪人
    2020-11-30 10:49

    WordNet works fine in NLTK 3.0. You are just accessing the lemmas (and names) in the wrong way. Try this instead:

    >>> import nltk
    >>> nltk.__version__
    '3.0.0'
    >>> from nltk.corpus import wordnet as wn
    >>> for synset in wn.synsets('dog'):
        for lemma in synset.lemmas():
            print lemma.name()
    
    
    dog
    domestic_dog
    Canis_familiaris
    frump
    dog
    dog
    cad
    bounder
    blackguard
    ...
    

    synset.lemmas is a method and does not have a __getitem__() method (and so is not subscriptable).

提交回复
热议问题