简体   繁体   English

IBM Watson Assistant:使用数组的对话节点条件表达式?

[英]IBM Watson Assistant: Expressions on dialog node condition using array?

For IBM Watson Assistant and a dialog node condition I want to check if the context variable long_name_context_var has one of the values 1,2,3,4,5 .对于 IBM Watson Assistant 和对话节点条件,我想检查上下文变量long_name_context_var是否具有值1,2,3,4,5 之一 The normal way would be正常的方法是

$long_name_context_var == 1 || $long_name_context_var == 2 || 
$long_name_context_var == 3 || $long_name_context_var == 4 || 
$long_name_context_var == 5

But it is visually too long.但它在视觉上太长了。 Thus, I want to shorten it.因此,我想缩短它。 I tried to use JSONArray.contains and Array literals as我尝试使用 JSONArray.contains 和 Array 文字作为

[1,2,3,4,5].contains($long_name_context_var)

but failed.但失败了。

Doesn't the node condition support array literals?节点条件不支持数组文字吗? Or would it give a syntax error?还是会出现语法错误?

The conditions on a dialog node in IBM Watson Assistant support SpEL-based expressions . IBM Watson Assistant 中对话节点上条件支持基于 SpEL 的表达式 This includes the contains function on JSON arrays .这包括JSON 数组上contains函数

Have you enabled debugging in the Try it to see the value of the context variable?您是否在尝试查看上下文变量的值中启用了调试? I assume your node works with the "visually too long" expression.我假设您的节点使用“视觉上太长”表达式。 Is the type of the context variable a string or a number?上下文变量的类型是字符串还是数字? Try using尝试使用

["1","2","3","4","5"].contains($long_name_context_var)

What definitely works is to assign the array to a context variable (in my test testme in the context editor in Try it ) and then use the following expression:绝对有效的是将数组分配给上下文变量(在Try it的上下文编辑器中的我的测试testme中),然后使用以下表达式:

$testme.contains("3")

Else you could try the indexOf function .否则你可以试试indexOf函数

尝试:

$long_name_context_var >= 1 || $long_name_context_var <= 5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM