Reputation:
I am trying to solve a nlp problem where i have a dict of words like :
list_1={'phone':'android','chair':'netflit','charger':'macbook','laptop','sony'}
Now if input is 'phone' i can easily use 'in' operator to get the description of phone and its data by key but problem is if input is something like 'phones' or 'Phones' .
I want if i input 'phone' then i get words like
'phone' ==> 'Phones','phones','Phone','Phone's','phone's'
I don't know which word2vec i can use and which nlp module can provide solution like this.
second issue is if i give a word 'Dog' can i get words like 'Puppy','Kitty','Dog','dog' etc ?
I tried something like this but its giving synonyms :
from nltk.corpus import wordnet as wn
for ss in wn.synsets('phone'): # Each synset represents a diff concept.
print(ss)
but its returning :
Synset('telephone.n.01')
Synset('phone.n.02')
Synset('earphone.n.01')
Synset('call.v.03')
Instead i wanted :
'phone' ==> 'Phones','phones','Phone','Phone's','phone's'
Upvotes: 3
Views: 8589
Reputation: 122022
WordNet indexes concepts (aka Synsets
) not words.
Use lemma_names()
to access root words (aka Lemma
) in WordNet.
>>> from nltk.corpus import wordnet as wn
>>> for ss in wn.synsets('phone'): # Each synset represents a diff concept.
... print(ss.lemma_names())
...
['telephone', 'phone', 'telephone_set']
['phone', 'speech_sound', 'sound']
['earphone', 'earpiece', 'headphone', 'phone']
['call', 'telephone', 'call_up', 'phone', 'ring']
Lemma being the root form or a word shouldn't have additional affixes so you'll not find plural or different form of the words as you have listed in the list of words you wanted.
See also:
Also, words are ambiguous and may need to be disambiguated by context or my Parts-of-Speech (POS) before you can get "similar" words, e.g you see that "phone" in the verb meaning is not exactly the same meaning as phone as in the "noun".
>>> for ss in wn.synsets('phone'): # Each synset represents a diff concept.
... print(ss.lemma_names(), '\t', ss.definition())
...
['telephone', 'phone', 'telephone_set'] electronic equipment that converts sound into electrical signals that can be transmitted over distances and then converts received signals back into sounds
['phone', 'speech_sound', 'sound'] (phonetics) an individual sound unit of speech without concern as to whether or not it is a phoneme of some language
['earphone', 'earpiece', 'headphone', 'phone'] electro-acoustic transducer for converting electric signals into sounds; it is held over or inserted into the ear
['call', 'telephone', 'call_up', 'phone', 'ring'] get or try to get into communication (with someone) by telephone
Upvotes: 6