Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find Synonyms for multi-word phrases

Tags:

python

nlp

nltk

Is it possible for the python library NLTK to suggest/create synonyms for groups of words?

For example; for the word/group "main course" can I use NLTK to get the synonyms "main dish", "main meal", "dinner" etc.?

Heres my code that works for single word synonyms but not multiwords:

from nltk.corpus import wordnet as wn
print wn.synset("eat.v.01").lemma_names # prints synonyms of eat
print wn.synset("main course.n.01").lemma_names # throws WordNetError
like image 231
sazr Avatar asked Oct 09 '22 06:10

sazr


1 Answers

Use an underscore:

print wn.synset("main_course.n.01").lemma_names
like image 111
Usagi Avatar answered Oct 12 '22 20:10

Usagi