Rivescript:在有条件的反应使用关键字触发

问题描述 投票:3回答:2

我的工作与Rivescript一个聊天机器人,我试图在条件反应,使用关键字触发。

在该网站上的tutorial,解释了可以使用...

[*]自选忽略消息的部分...

这工作正常,在最初的提示+ [*] you [*]但是当我尝试使用此方法来捕获包含yesno,因为它似乎打破它有条件响应的一部分有何回应?我没有得到一个错误代码,但它只是默认为- 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但没有运气在这里要么...

javascript chatbot rivescript
2个回答
1
投票

好了,我已经找到了使用对象宏的解决方案 - 但它是不是很优雅。

将该溶液返回用户的完全响应(与由所有单词小写 - 附lowercase - 数组中分离)以在test变量args对象宏。此阵列中的项目列举,以查看是否任何一个匹配在positivesnegatives阵列的项目(其基本上重复替换已经存在于rivescript“大脑”)。

如果有比赛,该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...

这似乎工作得很好,但我相信必须有一个更好的解决方案,哪怕是只有在清理对象宏本身(也许有一种方法可以把置换到对象宏??)。

我接受这个答案,但如果任何人有任何其他建议/解决方案,我还是会很乐意听到他们的声音。


0
投票

所以,我设法与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

出于某种原因,我猜我猜我不能在有条件的触发使用触发交替 - 有毕竟一个更完美的解决方案!

现在我会接受这个答案,离开了别人这个小的旅程谁可能会挣扎。

© www.soinside.com 2019 - 2024. All rights reserved.