python - 我想定义一个函数来提供聊天机器人的身份;但聊天机器人无法理解我的代码
问题描述
我想让我的聊天机器人自我介绍;但它不理解我的查询。
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
解决方案
推荐阅读
- vue.js - 创建一个包含 SCSS 的节点 (vue.js) 模块
- java - 如何自动将文件从一个服务器位置复制到另一个位置并从源位置移动?
- r - Dplyr 将活动日期数据重塑为每月级别
- java - 如何在 JAVA 中将 HTTP 标头添加到 SOAP 端点 uri?
- java - maven 适用于 windows powershell 和 cmd,但不适用于 git bash
- flutter - 取消 StreamSubscription
- java - 如何在Android Studio中使用Java的应用程序后台执行HttpURLConnection之类的任务?
- java - 单一 Web 服务中的多重传输支持
- c++ - 如何从需要基类指针的函数调用派生类的方法?
- python - django 表 2:将模板 url 硬编码到表行中