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

断了今生、忘了曾经 提交于 2019-12-01 04:08:37

问题


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?


回答1:


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:

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:

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):

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

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



来源:https://stackoverflow.com/questions/47148736/how-can-i-create-a-list-of-a-combination-of-attributes-in-api-ai-dialogflow

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!