EmJ
EmJ

Reputation: 4608

How to get the close words in WordNet in python

I am using WordNet as follows to get the synsets using python.

import nltk 
from nltk.corpus import wordnet
synonyms = []
for syn in wordnet.synsets("alzheimer"): 
    for l in syn.lemmas(): 
        synonyms.append(l.name())
print(set(synonyms))

However, the word alzheimer does not seem to be in WordNet as I get an empty synsets list. Then, I tried different other variants such as alzheimer disease, alzheimer's disease, alzheimers, alzheimer's, alzhemimers disease.

My question is; is it possible to get the word close to the word alzheimer in WordNet, so that I do not need to manually verify what is the term in WordNet to get the synsets.

I am happy to provide more details if needed.

Upvotes: 0

Views: 501

Answers (1)

qaiser
qaiser

Reputation: 2868

you can find similar word from a given word in wordnet vocabulary.

from nltk.corpus import wordnet as wn
wordnet_vocab = list(wn.all_lemma_names())

similar_string = 'alzheimer'
[word for word in wordnet_vocab if similar_string in word]
#op if exact word is not present,  you can get similar word which are present in wordnet vocab
["alzheimer's", "alzheimer's_disease", 'alzheimers']

Upvotes: 1

Related Questions