How can I create a list of a combination of attrib

2019-04-30 06:08发布

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?

标签: dialogflow
1条回答
孤傲高冷的网名
2楼-- · 2019-04-30 06:17

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

查看更多
登录 后发表回答