How To Get Similar Words Related To One Word?
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 c
Solution 1:
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:
- https://simple.wikipedia.org/wiki/Lemma_(linguistics)
- https://en.wikipedia.org/wiki/WordNet
- All synonyms for word in python?
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 ornot 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'] getortry to getintocommunication (with someone) by telephone
Post a Comment for "How To Get Similar Words Related To One Word?"