沃森助理 - 斯佩尔|更新数组

问题描述 投票:1回答:1

我试图使用Watson Assistant JSON编辑器 现在这是设置

Entities
@action = eat,run,play

Context Variable
$list = [0,0]

I want to update my list if an action is detected
List[0] will be the size
List[1] will be the position[0]

尝试使用Spel JSON

 "$list":"<? entities['action'] != null ? $list.set(0,entities['action'].size()) and $list.set(1,entities['action'].location[0]): $list.set(0,0) and $list.set(1,0) ?>"

如果添加了“和”运算符,则返回“True”| $名单=真 而不是我的数组更新到$ list ['size'] ['location']

我只能通过添加另一个包含布尔部分的上下文变量来实现这一点

"sample": "entities['action'] != null ? $list.set(0,5) and $list.set(1,5) : $list.set(0,0) and $list.set(1,0)"

任何想法如何使用1变量获得相同的输出?

ibm-watson watson-assistant
1个回答
0
投票

将列表设置为“True”的原因是这个表达式:"$list":"<? entities['action'] != null ? $list.set(0,entities['action'].size()) and $list.set(1,entities['action'].location[0]): $list.set(0,0) and $list.set(1,0) ?>"最终会将布尔检查的结果值分配给列表变量,从而覆盖表达式所做的修改。这是用于更新上下文变量的默认WA行为(例如,当您编写"my_string" : "value of the string"

如果你只想修改列表数组,你应该使用你建议的第二种方法使用另一个变量sample - 它将使用SpEL表达式的结果值进行更新,这样就不会覆盖list

© www.soinside.com 2019 - 2024. All rights reserved.