如何在 Rivescript-Python 中预处理特殊触发器?
How to preprocess a special trigger in Rivescript-Python?
我的 bot 将用户名存储在数据库中,并且数据库会不时向会话发送一条消息“setname username”。示例 rivescript:
+ setname *
- <set name=<formal>>
+ (what is my name|who am i)
- You're <get name>, right?
+ didntlike
- {topic=nlike}Why?
> topic nlike
+ *
- {topic=random}Thanks for charing.
< topic
+ *
- I don't have a reply for that.
- Try asking that a different way.
问题是当用户处于像“nlike”这样的主题时,由 * 退出并且我发送消息以设置名称,然后对话退出主题。
预计对话:
Me: hello
Bot: I don't have a reply for that.
Me: didntlike
Bot: Why?
Me: setname John
Bot:
Me: I didn't like because you are ugly.
Bot: Thanks for charing.
Me: Who am I?
Bot: You're John, right?
有没有办法在开始块中处理它?我尝试了不同的语法,但没有得到肯定的结果。我想到了类似的东西:
> begin
+ setname *
- <set name=<formal>>
+ request
- {ok}
< begin
一种解决方法是在所有主题中添加相同的触发器,但我需要一个更好的解决方案,因为随着我的 rive 文件变大,这种方法很容易出错。
==== 根据 Nelson 的回答尝试的代码 =====
> begin
+ request
- {ok}{topic=specialtriggers}
< begin
> topic specialtriggers
+ setname *
- <set name=<formal>>
< topic
+ (what is my name|who am i)
- You're <get name>, right?
+ didntlike
- {topic=nlike}Why?
> topic nlike
+ *
- {topic=random}Thanks for charing.
< topic
+ *
- I don't have a reply for that.
- Try asking that a different way.
我认为将主题添加到 {ok}{topic=specialtriggers} 会使该主题之外的所有触发器都失败。预处理后,Rivescript 应该回答它是否是特殊触发器,否则搜索普通触发器。
如果您的问题只是关于如何始终使用 begin
块预处理用户消息,答案是:
- 不需要在开始块中输入触发器。
+ request
是任何用户消息的通用表示。
- 如果您想限制触发器在开始块中匹配 仅 来自当前主题,一个
{ok}
标签就足够了。
修改你的代码如下
+ didntlike
- {topic=nlike}Why?
> topic nlike
+ *
- Thanks for charing.
< topic
> begin
+ request
- {ok} (Preprocessed in begin)
< begin
尝试按以下顺序发送消息 didntlike
、hello
,您将看到回复附加有 (Preprocessed in begin)
。
- 否则,开始块中的回复需要添加一个主题(which topic)从中获取触发器和回复。如果您想在
random
主题中获取 setname
的触发器,您可以将开始块添加到第一个代码片段的末尾。
RiveScript 代码
> begin
+ request
- {ok}{topic=random}
< begin
在这种情况下,向 setname
提供请求后的主题是主题 random
。
答案基于Noah Petherbridge's response on chatbots.org,一种可行的解决方案是使用主题继承:
> topic specialtriggers
+ setname *{weight=9991234}
- <set name=<star1>>
< topic
> topic random includes specialtriggers
// you don't actually need to put anything inside here, since triggers
// without a topic are in the "random" topic automatically, but this
// topic declaration line will make "random" include "important"
< topic
// but for your other topics, include the specialtriggers one
> topic nlike includes specialtriggers
+ *
- {topic=random}Thanks for caring.
< topic
我的 bot 将用户名存储在数据库中,并且数据库会不时向会话发送一条消息“setname username”。示例 rivescript:
+ setname *
- <set name=<formal>>
+ (what is my name|who am i)
- You're <get name>, right?
+ didntlike
- {topic=nlike}Why?
> topic nlike
+ *
- {topic=random}Thanks for charing.
< topic
+ *
- I don't have a reply for that.
- Try asking that a different way.
问题是当用户处于像“nlike”这样的主题时,由 * 退出并且我发送消息以设置名称,然后对话退出主题。
预计对话:
Me: hello
Bot: I don't have a reply for that.
Me: didntlike
Bot: Why?
Me: setname John
Bot:
Me: I didn't like because you are ugly.
Bot: Thanks for charing.
Me: Who am I?
Bot: You're John, right?
有没有办法在开始块中处理它?我尝试了不同的语法,但没有得到肯定的结果。我想到了类似的东西:
> begin
+ setname *
- <set name=<formal>>
+ request
- {ok}
< begin
一种解决方法是在所有主题中添加相同的触发器,但我需要一个更好的解决方案,因为随着我的 rive 文件变大,这种方法很容易出错。
==== 根据 Nelson 的回答尝试的代码 =====
> begin
+ request
- {ok}{topic=specialtriggers}
< begin
> topic specialtriggers
+ setname *
- <set name=<formal>>
< topic
+ (what is my name|who am i)
- You're <get name>, right?
+ didntlike
- {topic=nlike}Why?
> topic nlike
+ *
- {topic=random}Thanks for charing.
< topic
+ *
- I don't have a reply for that.
- Try asking that a different way.
我认为将主题添加到 {ok}{topic=specialtriggers} 会使该主题之外的所有触发器都失败。预处理后,Rivescript 应该回答它是否是特殊触发器,否则搜索普通触发器。
如果您的问题只是关于如何始终使用 begin
块预处理用户消息,答案是:
- 不需要在开始块中输入触发器。
+ request
是任何用户消息的通用表示。 - 如果您想限制触发器在开始块中匹配 仅 来自当前主题,一个
{ok}
标签就足够了。
修改你的代码如下
+ didntlike
- {topic=nlike}Why?
> topic nlike
+ *
- Thanks for charing.
< topic
> begin
+ request
- {ok} (Preprocessed in begin)
< begin
尝试按以下顺序发送消息 didntlike
、hello
,您将看到回复附加有 (Preprocessed in begin)
。
- 否则,开始块中的回复需要添加一个主题(which topic)从中获取触发器和回复。如果您想在
random
主题中获取setname
的触发器,您可以将开始块添加到第一个代码片段的末尾。
RiveScript 代码
> begin
+ request
- {ok}{topic=random}
< begin
在这种情况下,向 setname
提供请求后的主题是主题 random
。
答案基于Noah Petherbridge's response on chatbots.org,一种可行的解决方案是使用主题继承:
> topic specialtriggers
+ setname *{weight=9991234}
- <set name=<star1>>
< topic
> topic random includes specialtriggers
// you don't actually need to put anything inside here, since triggers
// without a topic are in the "random" topic automatically, but this
// topic declaration line will make "random" include "important"
< topic
// but for your other topics, include the specialtriggers one
> topic nlike includes specialtriggers
+ *
- {topic=random}Thanks for caring.
< topic