簡體   English   中英

Rivescript:在條件響應中使用關鍵字觸發器

[英]Rivescript: Using Keyword Triggers in Conditional Responses

我正在使用Rivescript在聊天機器人上工作,並嘗試在條件響應中使用關鍵字觸發器。

在網站上的教程中 ,它解釋了你可以使用...

[*]可選項忽略部分消息...

這在初始提示+ [*] 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*

更新:

也許,這是我使用的條件運算符的問題? 當我只是試圖找出一個是否包含在另一個值中時, == 我已經找到了工作草案,但這里沒有運氣......

好的,所以我找到了一個使用對象宏的解決方案 - 但它不是很優雅。

此解決方案將用戶完整響應(所有單詞以小寫 - lowercase - 在數組中分隔)返回到args變量中的test對象宏。 枚舉此數組中的項目以查看它們中的任何一個是否與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...

這似乎工作得很好,但我確信必須有一個更好的解決方案,即使它只是在清理對象宏本身(也許有一種方法將替換帶入對象宏??)。

我接受這個答案,但如果有人有任何其他建議/解決方案,我仍然會很高興聽到他們。

所以,我成功地與使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM