Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a list of a combination of attributes in API.AI (Dialogflow)

I have a requirement where I want to accept a list of 2 attributes from API.AI, for example, the user can say any of the following:

add 2 oranges and 3 bananas 2 my cart

add 2 oranges 3 bananas and 5 apples to my cart

So it should send a list of the combination of count and fruit-name to my application. Any suggestions?

like image 667
Sandeep Maller Avatar asked Nov 07 '17 01:11

Sandeep Maller


1 Answers

You can do this with Composite Entities.

First, create an entity that lists all of the fruit and their synonyms (let's call it fruit).

Then create a composite entity (let's call it number-of-fruit) that looks like this:

Screenshot of number-of-fruit entity

You just need one value, without synonyms, and it should contain the two parameters you wish to collect:

  • @sys.number-integer:number (the @sys.number-integer part represents the System Entity for integer, the :number part is the name we'll give this parameter)

  • @fruit:fruit (the @fruit part is the name of our fruit entity, the :fruit part is the name we'll give this parameter)

Now, when you add an example containing items in this format to an intent, you'll see that your new composite entity is detected:

enter image description here

However, the occurrences in the example are currently being treated as two separate parameters, not a list. To treat these entities as a list as opposed to two discrete items, select the second highlighted example and click the item that corresponds to the first parameter (in the screenshot it's the one with the blue text saying number-of-fruit):

enter image description here

Now, you'll see that the parameters section indicates that this parameter is a list:

enter image description here

Once you save and train, you can test that this works for an arbitrary length list via the console:

enter image description here

like image 156
Daniel Situnayake Avatar answered Nov 21 '22 07:11

Daniel Situnayake