1

我正在从事一个用于休闲的 AIML 项目,并遇到了潘多拉机器人。我想知道是否有办法将用户输入中的变量解析为其他语言(在本例中为 python)或框架,以便我们可以通过任何模板通过其他第三方 API 进行进一步操作?

例如,我想从用户那里获取日期,然后将其输入谷歌日历 API。有没有办法提取“日期”变量并将其解析为 Python(或任何其他语言)中的谷歌日历 API?

<category><pattern># 1 MAY 2016 #</pattern>
    <think>{{ date }}</think> #is there a way to parse "1 May 2016" as a 
                              #variable date in python? 
    <template>...
    </template>
</category>

最终,我试图实现的目标将是这样的对话:

User: Hi bot, could you check if I am available on 1 May 2016?
Bot: Nope, you have a gathering at Mike's! #(<--- Response rendered after 
                         checking user's schedule on 1 May via google calendar )

我探索了像 mustache 这样的模板引擎,但显然它不与 AIML(或者更确切地说是 xml)对话。有没有人可以为我指出一个可以帮助我入门的好例子/教程?

ps:我正在使用pandorabots API和python2.7

4

2 回答 2

2

在 pyAIML API 中,查找关键字“predicates”:

  • kernel.getPredicate('日期')
  • kernel.getBotPredicate('dat')

它返回使用设置的谓词

<set name="date"><star/></set>

然后你可以很容易地用python解析它。

但这让我更接近这个问题:我需要 AIML 做什么?AIML 在这里的附加价值是什么?

于 2016-07-05T12:13:09.390 回答
1

我也在寻找类似问题的信息。在@Berry Tsakala 提供的答案的帮助下......我能够找到解决问题的方法。这是上述示例案例的详细改进版本...可能对其他有相同问题的人有用...

<category><pattern>Hi bot, could you check if I am available on *</pattern>
<template>Let me check your schedules on <set name="date"><star/></set>
</template>
</category>

然后在你的python脚本中,你可以将它存储到一个变量中,

import aiml
kernel = aiml.Kernel()
kernel.learn("std-startup.xml")
kernel.respond("load aiml b")
while True:
    try:
        kernel.respond(raw_input("Enter your message >> "))
        appointment_date = kernel.getPredicate('date')
        print appointment_date

如果您发现任何错误或需要任何改进,请随时对答案进行更正。希望你觉得它有用 :)

于 2017-04-08T19:30:38.357 回答