How to find particular WordNet synset based on the meaning of the word in a sentence?

423 Views Asked by At

I'm trying to generate all synonyms of particular sentence using NLTK Python library. My idea is to perform POS tagging, than generate synonyms of all the words in the sentence based on POS tag and then recursively create all possible combinations to create "synonym sentences".

Currently, my biggest problem is that the code for obtaining synonyms of some word, generates synonyms of all possible meanings of that word (i.e. lemmas from all the synsets that word belongs to).

For example, in the sentence 'give me your number' the word 'number' probably means 'telephone number' and I would like to get only synonyms such as 'phone number' and 'telephone number' and not other synonyms of the word 'number' such as 'issue' and 'figure'.

I'm interested if there is any way for a synset (i.e. meaning) of the word in the sentence to be obtained in order to take only words from that particular synset as the synonyms. Finding a way of reducing a set of possible synonyms would also be very helpful.

Here is my code:

word_synonyms=set([])
for syn in wn.synsets(word, pos = pos_tag):
                    for lm in syn.lemmas():
                        word_synonyms.add(" ".join([lemma_el for lemma_el in lm.name().split('_')])) 
0

There are 0 best solutions below