首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >聊天机器人:如何正确确定意图?

聊天机器人:如何正确确定意图?
EN

Stack Overflow用户
提问于 2017-08-21 04:57:19
回答 1查看 104关注 0票数 0

例如,确定以下意图之间的区别的常用技术是什么?

  1. 目前的温度是多少?在这种情况下,直线上升的响应将是当前的温度.
  2. 目前的温度是22度吗?在这种情况下,适当的反应将是是或否。

我正在构建一个封闭域聊天机器人(如Siri),我想知道Python中是否有我能读到的技术。

EN

回答 1

Stack Overflow用户

发布于 2017-08-21 05:11:20

有一次,我开始编程,试图了解机器人是如何工作的。多小的世界啊。我几乎不记得我是怎么做的,但让我们假设您是根据机器人能够读取的事件构建聊天的。确定每个事件的答案的一种非常基本的方法是列出大量的IF ELIF内容以及嵌套行为(理想情况下分为方法)。

代码语言:javascript
复制
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")

然后,您必须对每种特定情况进行编码,如下所示:

代码语言:javascript
复制
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")

最后注意事项:--这绝不是最好的方法,但是如果您正在学习,我将在不太复杂的情况下完成工作,然后缓慢地改进代码。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45789547

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档