简体   繁体   中英

Watson Assistant - How to get size of specific entities

For example I have 3 different entities

@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> .

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

When one of the entity is not recognized ( null ), the value counted will be 0 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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