Rivescript:在条件响应中使用关键字触发器

Rivescript: Using Keyword Triggers in Conditional Responses

我正在使用 Rivescript 开发聊天机器人,并尝试在条件响应中使用关键字触发器。

在站点的 tutorial 中,说明您可以使用...

[*] optionals to ignore parts of a message...

这在初始提示 + [*] you [*] 中工作正常,但是当我尝试使用此方法捕获 any 包含 yes 或 [=15] 的响应时=] 作为条件响应的一部分,它似乎打破了它?我没有收到错误代码,但它只是默认为 - So, back to the matter at hand... 作为响应。

  + [*] you [*]
  - Oh, so we're talking about me now?

  + *
  % oh so we are talking about me now
  * <star> == [*] no [*]  => Whatever...
  * <star> == [*] yes [*] => This should be fun.{topic=myself}
  - So, back to the matter at hand...

如果这可行,我希望对话能够进行,例如:

User: What do you do?
Bot: Oh, so we're talking about me now?
User: Yes, I suppose so
Bot: This should be fun.

那么,有没有什么方法可以在没有 显式 用户输入的情况下使用条件响应?而是 包含 特定响应?我想这是在两个实例中使用 * 的问题,既是 <star> 又是 [*],但无法在框架内找到解决方案?也许我错过了什么?我也尝试过使用 *yes**no*.

更新:

也许是我使用的条件运算符有问题?也许 == 不是比较两个值的正确方法,当我只是想找出一个值是否 包含在另一个值中时 吗?我已经找到了 Working Draft 但这里也没有运气......

好的,所以我找到了一个使用对象宏的解决方案——但它不是很优雅。

此解决方案 returns 用户对 [=13] 中的 test 对象宏的完整响应(所有单词都小写 – 用 lowercase – 分隔在一个数组中) =] 变量。枚举此数组中的项目以查看它们是否与 positivesnegatives 数组中的项目匹配(它们本质上是已存在于 rivescript 'brain' 中的重复替换)。

如果匹配,action 变量更新为 yesno 并且循环中断,如果没有匹配则 action 变量保持 undefined。这个 action 变量然后返回到条件响应并由 rivescript 评估以查看它是否符合任何条件。

> object test javascript
    let positives = ['yes', 'yeah', 'yep', 'yup', 'yh', 'ya', 'y', 'sure'];
    let negatives = ['no', 'nope', 'na', 'nah', 'pass'];
    var action = 'undefined';
    for (var i = 0; i < args.length; i++) {
      if (positives.indexOf(args[i]) !== -1) {
        action = 'yes'
        break;
      } else if (negatives.indexOf(args[i]) !== -1){
        action = 'no'
        break;
      } else {

      }
    }
    return action;
< object

// In the topic/main section

+ [*] you [*]
- Oh, so we're talking about me now?

+ *
% oh so we are talking about me now
* <call>test <lowercase></call> == no        => Whatever...
* <call>test <lowercase></call> == yes       => This should be fun.{topic=myself}
* <call>test <lowercase></call> == undefined => So, back to the matter at hand...
- So, back to the matter at hand...

这似乎工作得很好,但我相信一定有更好的解决方案,即使它只是清理对象宏本身(也许有一种方法可以将替换带入对象宏?? ).

我接受这个答案,但如果有人有其他选择suggestions/solutions,我仍然很乐意听取他们的意见。

因此,我设法与 Noah Petherbridge 取得了联系,他们在 Rivescript 上工作并且非常友好地花时间纠正我的理解:

+ [*] you [*]
- So you are talking about me now?

+ [*] (yes|no) [*]
% so you are talking about me now
* <star> == yes => yes answer
* <star> == no => no answer
- default, shouldn't happen answer

出于某种原因,我想我假设我不能在条件触发器中使用触发器交替——毕竟有一个更优雅的解决方案!

我现在接受这个答案,把这段小旅程留给可能正在挣扎的其他人。