NLTK.corpus 和 wordnet

NLTK.corpus and wordnet

我在使用 nltk.corpus 和 wordnet 时遇到了一个小问题。它似乎无法找到 'yes' 的同义词,即使 thesaurus.com 说有,我如何才能提取我的 'yes' sysnoyms 以便正确评估底部部分的输入。

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()

我以前尝试过做类似的事情,但 wordnet 不是我的最佳选择,但你可以在这里看看: Wordnet Find Synonyms

我向您推荐 http://www.conceptnet.io/,它对您的任务来说更好更容易,它是一个开放的数据集,您可以免费访问它