例如,确定以下意图之间的区别的常用技术是什么?
我正在构建一个封闭域聊天机器人(如Siri),我想知道Python中是否有我能读到的技术。
发布于 2017-08-21 05:11:20
有一次,我开始编程,试图了解机器人是如何工作的。多小的世界啊。我几乎不记得我是怎么做的,但让我们假设您是根据机器人能够读取的事件构建聊天的。确定每个事件的答案的一种非常基本的方法是列出大量的IF ELIF内容以及嵌套行为(理想情况下分为方法)。
def handleevent (message, user, date, font, whatever):
if "current temperature" in message:
send_text_to_chat("The temperature is 22 degrees")
elif "is current temperature" in message and "?" in message:
specific_temp_asked(message)
elif "potato" in message: # you could do hundred of behaviours, and nested ones.
if user == "apple":
send_text_to_chat("Hi apple!")
else:
send_text_to_chat("I am a potato bot")
elif "who am I?" in message: # example using the event data
send_text_to_chat("you are " + user)
else:
send_text_to_chat("Be more specific")然后,您必须对每种特定情况进行编码,如下所示:
def specific_temp_asked(message):
temperature = None
split_message = message.split(" ")
for i in split_message:
try:
int(i)
temperature = i
break
except:
pass
if not temperature == None:
real_temperature = check_temp(somehow)
if real_temperature == temperature:
send_text_to_chat("Yes")
else:
send_text_to_chat("Nope")最后注意事项:--这绝不是最好的方法,但是如果您正在学习,我将在不太复杂的情况下完成工作,然后缓慢地改进代码。
https://stackoverflow.com/questions/45789547
复制相似问题