1

I am building a chatbot in Node.js and have been using aiml-high. I am trying to access the predicates of the AIML so that I can store them in variables which I will use later on. I know that in Python there is a way to get the predicates like so:

name = kernel.getPredicate("name", sessionId)

So, here is my question in more detail. Below is a category from my AIML file.

<category>
    <pattern>DO YOU SPEAK <set name="language">*</set></pattern>
    <condition name="language">
      <li value="english">Yes. I do speak <get name="language"/>.</li>
      <li value="English">Yes. I do speak <get name="language"/>.</li>
      <li>Sorry. I don't speak <get name="language"/>. Maybe one day I will learn though.</li>
    </condition>
  </category>

If the user says "Do you speak French", the language, which in this case is "French", is stored here:

<set name="language:>*</set>

Now, the language is remembered and can respond accordingly.

<li>Sorry. I don't speak <get name="language"/>. Maybe one day I will learn though.</li>

...replacing the <get name="language"/> with the language that the user had input. I would like to access that language predicate in my JavaScript so I can use it later. So, I was wondering if anyone has built a chatbot in Node.js and would have insight as to how I would save these predicates.

4

1 回答 1

0

因此,自从发布这个问题以来,我一直在查看 aiml-high 节点包的代码。我最终找出了用户生成的变量的存储位置,并在 aiml-high 节点包中的 aiml-high.js 中添加了两个新方法。

我添加的第一个方法是返回所有存储变量的方法:

this.getStoredVariables = function() {
  return storedVariableValues;
}

下一个方法允许您选择要返回的存储变量而不是整个对象。

this.getSpecificStoredVariable = function(v) {
  return storedVariableValues[v];
}

因此,即使这两种方法很简单,并且大多数开发人员只需查看高目标代码本身就可以完成我所做的事情,但我希望将来寻找类似答案的人会遇到这个答案,所以他们不会不必自己查看代码。

另外,我添加了第三种方法来获取机器人的属性。

this.getAttributes = function() {
   return botAttributes;
}
于 2017-02-23T19:02:13.967 回答