【问题标题】:SpEL Collection Selection in IBM ConversationIBM 对话中的 SpEL 集合选择
【发布时间】:2018-04-04 10:39:54
【问题描述】:

这仅与 IBM Watson Conversation 用户有关。

我正在尝试将上下文变量设置为用户在 @sys-date 属性中输入的唯一“有效”日期。这里的有效日期是 1900 年 1 月 1 日之后和现在之前。根据 SpEL 定义,我应该选择带有.?[value > expression] 的列表。其中 value 或 #this 是当前列表项。

"context": {
    "date": "<? @sys-date and @sys-date.values ? @sys-date.values.?[value.after('1900-01-01') and value.before(now())] : null ?>",
    "thisWorks": "<? {0,1,2,3,4}.?[false] ?>",
    "thisDoesNot": "<? {0,1,2,3,4}.?[value > 1] ?>"
}

thisWorks = [] 其他一切都会引发错误。 我曾尝试使用#this,但 watson 会转换为 (intent == 'this'),并且像 \#this 一样转义会在尝试保存之前引发错误。

IBM 表示它支持 SpEL,并且部分定义是集合选择。即使在this blog post 中,它也表示支持这种类型的功能。但是没有它的例子,我尝试过的一切都会导致错误。

有没有其他人在 Watson Conversation 中使用过集合选择并提供示例?

【问题讨论】:

    标签: ibm-cloud ibm-watson spring-el watson-conversation


    【解决方案1】:

    不确定您的问题,但也许这些信息可以帮助您。

    尝试将日期保存在一个context 变量中,例如:

    {
      "context": {
        "date": <? @sys-date ?>;
      },
      "output": {
        "text": {
          "values": [
            "Are you sure about this $date?"
          ],
          "selection_policy": "sequential"
        }
      }
    }
    

    然后,提出你的条件......

    查看$date 是否在将来使用:

    if bot recognizes now().before($date) or @sys-date.before($date)
    response "Ok, the date is before $date."
    

    如果过去:

    now().after($date) or @sys-date.after($date)
    response "Ok, the date is after $date, in this case is one invalid date"
    

    Obs.:您可以在条件中使用此示例。在您的情况下是在 if bot 识别中使用“有效”日期。

    【讨论】:

      【解决方案2】:

      我能够过滤列表的唯一方法是使其成为对象列表。例如:

      <? {1:1, 2:2, 3:3 }.?[value < 3 ].![value] ?>
      

      希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 2022-09-27
        • 1970-01-01
        • 2015-11-16
        • 2015-05-15
        • 1970-01-01
        • 2013-03-26
        • 2022-06-11
        • 1970-01-01
        • 2013-10-19
        相关资源
        最近更新 更多