Search code examples
pythonnltkwordnet

Extract synonyms using Wordnet


I am having a minor issue with nltk.corpus and wordnet. It can't seem to find synonyms for 'yes', even though thesaurus.com says there is, how I can I extract my 'yes' sysnoyms in order to properly assess input into that bottom section.

import textblob as txtnlp
from nltk.corpus import wordnet
def text_extraction():
    yes_ls = []
    for synset in wordnet.synsets("yes"):
        for lemma in synset.lemmas():
            yes_ls.append(lemma.name())
    init_conversation = str(input('Hello there my name is Therpibot 2.0, your name is? '))
    blob_1 = txtnlp.TextBlob(init_conversation)
    fragments_name = blob_1.words
    print(f'Hello there {fragments_name[0]}!', end=' ')
    print('My purpose is to make your day better through some cognitive behavioral therapy.')
    init_response = str(input('Would like to engage in a talk session? '))
    if init_response.lower() in yes_ls:
        therapy()
    #ex_1 = list(i.tags for i in fragments)
    #print(ex_1)
def therapy():
    print('Hi')

if __name__ in "__main__":
    text_extraction()

Solution

  • i've tried to do something like that before but wordnet wasn't my best choice but you can take a look here: Wordnet Find Synonyms

    and i recommend http://www.conceptnet.io/ for you , it's much better and easier for your task , it's an open data set you can access it for free