John Kanti February 2016

How to solve iteration issue on data set in Python when using WordNet?

I try to use wordnet in python to list some of synonyms of a (word) I have the following code:

for i,j in enumerate(wn.synsets('dog')):
  print "Meaning",i, "NLTK ID:", j.name
  print "Definition:",j.definition
  print "Synonyms:", ", ".join(j.lemma_names)
  print

I use Python 2.7.10 and I got the following error :

print "Synonyms:", ", ".join((j.lemma_names))
  TypeError: can only join an iterable

How could I solve this issue ?

Answers


soon February 2016

According to the documentation, lemma_names is a method - you should call it in order to retrieve names:

print "Synonyms:", ", ".join(j.lemma_names())
#                                         ^^

Post Status

Asked in February 2016
Viewed 2,600 times
Voted 4
Answered 1 times

Search




Leave an answer