首页 > 解决方案 > 我想定义一个函数来提供聊天机器人的身份;但聊天机器人无法理解我的代码

问题描述

我想让我的聊天机器人自我介绍;但它不理解我的查询。


    GREETING_INPUTS = ("hello", "hi", "greetings", "sup", "what's up","hey",)
    GREETING_RESPONSES = ["hi", "hey", "*nods*", "hi there", "hello", "I am glad! You are talking to me"]
     def greeting(sentence):
        for word in sentence.split():
            if word.lower() in GREETING_INPUTS:
                return random.choice(GREETING_RESPONSES)
        Identy_Input = ("Who are you?","What is your name?","What's your name")
        Identy_Response = ["I am Robo, your virtual chatbot","THis is Robo, your virtual assistant"]

     def identity(sentences):
        for word in sentences.split():
            if word.lower() in Identy_Input:
                return random.choice(Identy_Response)

对话是这样的:

ROBO: My name is Robo. I will answer your queries about Chatbots. If you want to exit, type Bye!
who are you
ROBO: I am sorry! I don't understand you
who are you?
ROBO: I am sorry! I don't understand you
Hi
ROBO: hi there
What's your name?
ROBO: I am sorry! I don't understand you

标签: pythonnltkcosine-similaritytfidfvectorizer

解决方案


推荐阅读