sazr
sazr

Reputation: 25938

Finding synonyms for a certain word creates a WordNetError

I am attempting to get synonyms for a word using the python library NLTK.

My Problem: Some words create an error when I use them. For example 'eat' throws a WordNetError of "WordNetError: no lemma 'eat' with part of speech 'n'". What does that mean? How can I retrieve synonyms for the word eat?

Here's my code, note how words like 'dog' do work:

from nltk.corpus import wordnet as wn
print wn.synset("dog.n.01").lemma_names
print wn.synset("eat.n.01").lemma_names

Also is it possible to get synonyms for a group of words? For example; for 'main course', can I get the synonyms 'main dish', 'main meal', 'dinner'?

Upvotes: 1

Views: 845

Answers (1)

Danica
Danica

Reputation: 28856

The error says no lemma 'eat' with part of speech 'n'. That means that "eat" isn't in WordNet as a noun. Try it as a verb:

>>> wn.synset('eat.v.01').lemma_names
['eat']

Upvotes: 1

Related Questions