'How to capture the multiple values of one entity in IBM watson assistant after asking slot?

In my Watson Assistant app, I want to capture the multiple entities in the context and also have a slot to ask a question to user. Here is an example:

  • User: I want to fly from Toronto to Boston

And the Watson correctly detects:

intent: 'booking', @city:'Toronto', @city:'Boston'

Now I have a slot which asks for booking class:

  • Watson(Slot): Which class would you like?
  • User: Economy

At this point, the context only have first value for the @city entity i.e. Toronto. I understand from my googling that I can access @city[0] and @city1. And I tried to capture it in the context by doing the following but the value I'm getting is None.

enter image description here

How can I correctly capture both cities @city:Toronto, @city:Boston and at the same time entity @class:economy ?



Solution 1:[1]

The slots are smart - when there are multiple entities of the same type and more slots that match the entity of the same type then when a slot matches the first entity it will be "eaten" and not available for other slot - hence the next slot matching the same entity type will match any other entity of the same type. To achieve what you want to do simply define the slots in a following way (so both of them match simply the @city entity).

enter image description here

Solution 2:[2]

Revisiting this as there has been changes to Watson Assistant to make this easier.

1. Create two Entities. @fromCity and toCity.

2. Fill each entity with the same values. Names of locations.

3. Create your intent with questions like below.

I want to fly from Toronto to Boston
I have to get to Boston from Toronto ASAP. 
I want to get a flight to New York
I'm in Texas and need to fly to San Diego

4. On the intents page select each city and flag them as either the @fromCity or @toCity. This creates contextual entities.

enter image description here

Now when it trains it will understand the entities in the context of the sentence. It will also understand locations you have not trained it on.

More detailed example here.

Solution 3:[3]

I'm replying here not only for you, but also for myself, since I have had this question a couple times. This is how I've handled it.

You can use SPEL, the expression language for watson to map all the literal values that match an entity and put them into a context variable like so inside the json configuration:

"context": {
    "ReferenceNumber": "@ReferenceNumber.literal",
    "ReferenceNumbersRunAdd": "<?$ReferenceNumbersMultiple.addAll(entities['ReferenceNumber'].![literal]) ?>"
  }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Michal Bida
Solution 2 Simon O'Doherty
Solution 3 Aaron Wilson