[英]Rivescript: Using Keyword Triggers in Conditional Responses
我正在使用Rivescript在聊天机器人上工作,并尝试在条件响应中使用关键字触发器。
在网站上的教程中 ,它解释了你可以使用...
[*]
可选项忽略部分消息...
这在初始提示+ [*] you [*]
工作正常,但是当我尝试使用此方法捕获任何包含yes
或no
响应作为条件响应的一部分时,它似乎打破了它? 我没有得到错误代码,但它只是默认为- 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*
。
更新:
也许,这是我使用的条件运算符的问题? 当我只是试图找出一个是否包含在另一个值中时, ==
我已经找到了工作草案,但这里没有运气......
好的,所以我找到了一个使用对象宏的解决方案 - 但它不是很优雅。
此解决方案将用户完整响应(所有单词以小写 - lowercase
- 在数组中分隔)返回到args
变量中的test
对象宏。 枚举此数组中的项目以查看它们中的任何一个是否与positives
或negatives
数组中的项目匹配(这些项目基本上是已存在于rivescript“大脑”中的重复替换)。
如果匹配,则action
变量更新为yes
或no
并且循环中断,如果没有匹配则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...
这似乎工作得很好,但我确信必须有一个更好的解决方案,即使它只是在清理对象宏本身(也许有一种方法将替换带入对象宏??)。
我接受这个答案,但如果有人有任何其他建议/解决方案,我仍然会很高兴听到他们。
所以,我成功地与使用Rivescript的Noah Petherbridge取得了联系,他非常善意地花时间纠正我的理解:
+ [*] 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
出于某种原因,我想我认为我不能在条件触发器中使用触发器替换 - 毕竟有一个更优雅的解决方案!
我现在会接受这个答案,并为可能正在挣扎的其他人留下这个小小的旅程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.