【问题标题】:I need a logic understanding for Rivescript Conditional syntaxes我需要对 Rivescript 条件语法有逻辑理解
【发布时间】:2022-05-23 22:33:26
【问题描述】:
! var name = Alex

+ my name is *
* <formal>   == <bot name> => Wow, we have the same name!<set name=<formal>>
* <get name> == undefined  => <set name=<formal>>Nice to meet you!
- <set oldname=<get name>><set name=<formal>> I thought your name was <get oldname>?

我不明白 rivescript 解释器将如何按顺序解释此代码,尤其是第 4 行让我很困惑。有人可以告诉我这段代码是如何逐行执行的吗?

例如:- 在第 4 行 (),如果我必须返回用户所说的名字,那么我仍然可以在没有这个逻辑的情况下这样做(如上所述)并设置变量名代替 .

因此,如果用户说 Alex,然后说 John。第 4 行将被触发,机器人会告诉用户他的名字是 Alex.

【问题讨论】:

    标签: python chatbot rivescript conversational-ai conversational-design


    【解决方案1】:

    在每种语言中,脚本首先被标记化,然后解析为 AST(抽象语法树),然后解释 AST。

    来自https://github.com/aichaos/rivescript-python/blob/master/rivescript/parser.py 的 Rivescript AST 示例

    ...
    "triggers": [   # array of triggers
                                {
                                    "trigger": "hello bot",
                                    "reply": [], # array of replies
                                    "condition": [], # array of conditions
                                    "redirect": None, # redirect command
                                    "previous": None, # 'previous' reply
                                },...
    
    

    如果你没有用自己的语言实现程序的经验,我建议你试试这门课程https://github.com/kanaka/mal/blob/master/process/guide.md

    【讨论】:

      猜你喜欢
      • 2020-08-02
      • 1970-01-01
      • 1970-01-01
      • 2015-10-24
      • 1970-01-01
      • 1970-01-01
      • 2016-12-14
      • 1970-01-01
      • 2020-03-22
      相关资源
      最近更新 更多