问题
I'm looking at this link:
Actions and parameters | Dialogflow Documentation | Google Cloud
Where it explains 'List parameters' it uses these examples:
- "I want apples"
- "I want apples and oranges"
- "I want apples, oranges, and bananas"
Then I was wondering if it's possible to set up a 'List parameter' to handle something like this:
"I want 7 apples, 8 oranges and 12 bananas"
So you'd have a sort of Key - Value pair list.
Pseudo code:
List<KeyValuePair<string, int>> fruitList = new List<KeyValuePair<string, int>>();
KeyValuePair<string, int> applesItem = new KeyValuePair<string, int>("apples", 7);
KeyValuePair<string, int> orangesItem = new KeyValuePair<string, int>("oranges", 8);
KeyValuePair<string, int> bananasItem = new KeyValuePair<string, int>("bananas", 12);
fruitList.Add(applesItem);
fruitList.Add(orangesItem);
fruitList.Add(bananasItem);
So, in dialogflow, the $FruitList
parameter would be something like the Key - Value pair list fruitList
above.
The number part should then match with the @sys.cardinal
entity. And the fruit part should match to a custom entity @Fruits
with a bunch of fruits in it.
Pseudo code: List<KeyValuePair<@sys.cardinal, @Fruits>>
How can I make an 'Intent' in Dialogflow that can do this? Is it possible?
Help / Advice appreciated.
回答1:
Im not sure if you could get dialogflow return a key value pair object, but using composite entities you can create an entity which consists of an amount (number) and a fruit (fruit entity). You could call this composite entity order and make that a list in the parameters in your intent. When you enter
"I want 7 apples, 8 oranges and 12 bananas"
You should get a list with 3 order entities ( 7 apples, 8 oranges, 12 bananas)
https://cloud.google.com/dialogflow/docs/entities-developer#developer_composite
来源:https://stackoverflow.com/questions/57855562/how-to-setup-a-complicated-islist-parameter-in-dialogflow