[英]Watson Assistant - How to get size of specific entities
For example I have 3 different entities 例如我有3个不同的实体
@action = eat,run,walk
@person = Michael, John, Fred
@emotion = angry,sad,happy
I want to count user entered action and person entities 我想计算用户输入的动作和人物实体
If bot recognizes
entities['action'].size() + entities['person'].size() > 2
Any other way to achieve this? 还有其他方法可以做到这一点吗?
To account for one of the entities not being recognized, you can use ternary operator <Expression> ? <what_to_do_when_true> : <what_to_do_when_false>
要说明未被识别的实体之一,可以使用三元运算符
<Expression> ? <what_to_do_when_true> : <what_to_do_when_false>
<Expression> ? <what_to_do_when_true> : <what_to_do_when_false>
. <Expression> ? <what_to_do_when_true> : <what_to_do_when_false>
。
So, in your example the condition would look like this: ((entities['action'] != null ? entities['action'].size() : 0) + (entities['action'] != null ? entities['person'].size() : 0)) > 2
因此,在您的示例中,条件看起来像这样:
((entities['action'] != null ? entities['action'].size() : 0) + (entities['action'] != null ? entities['person'].size() : 0)) > 2
When one of the entity is not recognized ( null
), the value counted will be 0
. 如果无法识别其中一个实体(
null
),则计数值为0
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.