简体   繁体   中英

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 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' 

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, eg 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM