简体   繁体   中英

How to get more synonyms using NLTK Wordnet?

So I am using this code to get the synonyms.

from nltk.corpus import wordnet 

def Get_Syn(text):
    xx = []
    sentence1 = text.split(" ")
    for i in sentence1:
        if i not in stopwords:
            for syn in wordnet.synsets(i):
                for name in syn.lemma_names():
                      if name != i.lower():
                               xx.append({i:name}) 
                      else: 
                        pass
    return xx

Now, if I use Get_Syn('recieve') , I recieve an empty list (no synonyms). But, if I use Get_Syn('get') , this is the list I get:

[{'get': 'acquire'},
 {'get': 'become'},
 {'get': 'go'},
 {'get': 'let'},
 {'get': 'have'},
 {'get': 'receive'},
 {'get': 'find'},
 {'get': 'obtain'},
     .
     .
     .
]

As we see, recieve is a synonym of get , but get is not a synonym of recieve .

So how can I get get when I search for recieve . Is there way to map the two together?

your function is right. you have vocab error to write receive. recieve is wrong please check your word again.

Get_Syn('receive')

[
 {'receive': 'have'},
 {'receive': 'get'}, <===
 {'receive': 'find'},
 {'receive': 'obtain'},
 ...

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