Map entities to other entites

hi, I am building a simple food ordering bot. In this I have a take_order intent in which two entities will be extracted food_item and quantity, both of these entities have list types in slots, for example if a user message like this comes:

I would like to have [one] (quantity) [chicken burger] (food_item) and [two] (quantity) [fries] (food_item)

slot for this example will be: slot{“quantity”: [“one”, “two”], “food_item”: [“chicken burger”, “fries”]}

in the action user_take_order I will be multiplying quantity of each item to its price and giving total bill to the user.

But I have a problem, in a complex case when user do not provide a quantity for the food_item, I will be assuming the default quantity to one but the problem occurs when user orders three items and do not provide quantity for only the second item, for example:

I would like to have [one] (quantity) [chicken burger] (food_item), [fries] (food_item) and [two] (quantity) [soft drinks] (food_item)

in this example no quantity is provided for the fries and slots filled: slot{“quantity”: [“one”, “two”], “food_item”: [“chicken burger”, “fries”, “cold drink”]}

in the action user_take_order I would like to do this:

1 x price_of_chicken_burger
1 x price_of_fries
2 x price_of_cold_drink

but the problem is that in quantity slot I have only quantities of chicken burger and cold drink and I do not have a clue that user did not mention the quantity of fries( I want to set quantity of fries as 1 “default case”)

have I choose the wrong types for slots quantity and food_item?

slots:
  food_item:
    type: list
  quantity:
    type: list

I think this issue can be solved in several different ways. The first one that I can think of is (this is just a quick way of doing it that passed in my mind I know this can be improved quite a lot):

So you have the message:

One chicken burger, fries and two soft drinks

Get the whole message using:

 message = tracker.latest_message.get('text')

Usually as written in your example the quantity will come before the food_item.

So you could for example, divide the string using the food_item as parameter like this:

 message.split("chicken burger")

This would return to me:

['One ', ', fries and two soft drinks']

After that I would check if the quantity item is present in the first item of the list (since the quantity comes before the item).

If it is present on the first item of the return. That would mean that quantity is for that item. If not. You would iterate to the next one. Not sure if it is clear?

As I said this is the first way that I thought on how to do it. But probably there are better ones :wink:

1 Like