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 "test.py", line 6, in <module> for synWords in synSet.lemma_names: TypeError: 'instancemethod' object is not iterable
Does anyone know what the problem could be?
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:
synonymListis not defined
- List will not have an
addmethod even if
- You better name your variable