Error when accessing synonyms in python using nltk?

I have written a very simple piece of code to try and print the synonyms associated with a word.

import nltk from nltk.corpus import wordnet as wn wordNetSynset = wn.synsets('small') for synSet in wordNetSynset: for synWords in synSet.lemma_names: synonymList.add(synWords) print synonymList

However, I get the following error:

Traceback (most recent call last): File "", line 6, in <module> for synWords in synSet.lemma_names: TypeError: 'instancemethod' object is not iterable

Does anyone know what the problem could be?

-------------Problems Reply------------

In Nltk 3, the lemma_names has been changed to a method from an attribute.

So you have to call the method

for synWords in synSet.lemma_names():

Other minor changes required are:

  • synonymList is not defined
  • List will not have an add method even if synonymList is defined
  • You better name your variable synonymSet
Category:python Views:0 Time:2018-03-29

Related post

Copyright (C), All Rights Reserved.

processed in 0.168 (s). 11 q(s)