1

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?

  • 1
    What is the scenario or question? Could you provide more context? You seem to know how to get to the size. – data_henrik Apr 03 '19 at 09:44
  • how can I add the size of two entities using the condition the example above is not working so I was trying to look for another way I can only achieve this by creating a context variable that holds the count and with the help of multiple response – user3815221 Apr 04 '19 at 03:40
  • I have trouble reading your comment. Could you separate sentences by comma or period / full stop? Do you want to add two values before comparing? Where do you place that condition? – data_henrik Apr 04 '19 at 08:28
  • Sorry for that.. Yes i was trying to add 2 values of entities size, I want to place it on the condition (If Bot Recognizes) – user3815221 Apr 05 '19 at 01:35
  • basically it doesn't continue adding the 2 entity size if one is null, Is there a way to add it even if one entity is null? – user3815221 Apr 05 '19 at 03:30

1 Answers1

0

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

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.

Michal Bida
  • 1,316
  • 9
  • 24