Identify number associated with each entity in Dialogflow - dialogflow-es

I am not sure if this title is appropriate for the question, so let me explain in detail what is it that I am trying to achieve. This is not my actual project scenario I am using this as an example.
Consider a scenario where a user is trying to buy fruit's.
The user can say to bot:
I need 2 apples and an orange
I need 1 apple and 1 orange
I need an apple and 2 oranges
I need an apple and an orange
Suppose I have an entity fruits that identifies fruits and I am using #sys.number to identify the number of fruits.
In my current logic, I am taking the entities fruits and #sys.number as list and mapping each based on the index, ie first fruit in list will be mapped to 1st number in the other list, and if the number's list doesn't have a corresponding index for a fruit in fruits list, I'll assume it as 1.
This is just an adjustment and wont work for message type 3. mentioned above.
Ideally I have to identify which number was mentioned against which fruit. Is there any way to do this ?
I will be able to do this by looking at the queryText in fulfillment request and parsing the text to see the order, but is there a way to make dialog flow itself to provide this information for us ?

Here, I've tried your scenario on my own.
I'm not sure whether it's the best practice or not but In this configuration, where I've separated every fruit and its number by a separate parameter. And by adding some appropriate training phrases, it's working as expected (As shown in the simulation window on the righ side).
It will also work fine if you say just 1 Apple or 2 Oranges.
In the earlier configuration, I've made single fruit and number parameter with list support but it gives problem, and in future, if fruits are increased then it's hard to maintain indexes. So I think it's better to have separate parameters for each fruit rather than having a list.

Related

Sort and find Top and Bottom 5 values and their corresponding names

I know this is not the first time someone is asking a similar question, but me trying to execute what I found out in other answers is not working exactly as how I want it to be. I hope someone here could help me.
I got four columns, the first one is the Product Name, and the last one is its P/L%. I want to sort out top and bottom 5 P/L% value along with their corresponding Product Name. I am attaching the screenshot of a sample scenario in case if you couldn't understand what I explained.
I tried the (sort(filter)) method as found somewhere else, but it actually messed up with the second and third columns. I hope someone here can give me some simple ways.
My solution considers the case when multiple products has same value in P/L% and I use a Table object for displayed data.
Formulas to use
Top 5 Gainers values
=LARGE(ProductTable[P/L%]; ROWS($H$3:H3)), and copy down
Top 5 Gainer values
Top 5 Gainers products name
=INDEX(ProductTable[Product Name];AGGREGATE(14;6;(ROW(ProductTable[P/L%])-ROW(D$2)+1)/(ProductTable[P/L%]=H3);COUNTIF($H$3:H3;H3))), and copy down
Top 5 Gainers products name
Top 5 Loosers values
=SMALL(ProductTable[P/L%];ROWS($H$3:H3)), and copy down
Top 5 Loosers values
Top 5 Loosers products name
=INDEX(ProductTable[Product Name];AGGREGATE(14;6;(ROW(ProductTable[P/L%])-ROW(D$2)+1)/(ProductTable[P/L%]=K3);COUNTIF($K$3:K3;K3))), and copy down
Top 5 Loosers products name
Short Explanation
You must use LARGE and SMALL functions when you want to get the largest or the smallest value in a data array.
AGGREGATE function is a little bit complex to explain here so I recommend you this link to understand better. Basically, I use this formula to get the row of the gainer or looser product name into INDEX function.
ROWS($H$3:H3) returns 1, but when you copy down this formula, you get 2, 3, and so on. This is a nice way to expand the query if you need more than top 5 values.
Similar problem in:
https://www.excelforum.com/excel-formulas-and-functions/1208726-index-match-large-and-duplicates.html

Excel COUNTIFS OR function for non-exclusive match

I have a spreadsheet of orders of fruits.
The varieties of fruits contained in a given order are all written in the same cell, coma separated.
If I want to get the number of orders that include bananas, I do the following
=COUNTIFS('Order List'!C:C,F$1,'Order List'!AG:AG,"*Banana*")
If I want to get the number of orders that include oranges, I do the following
=COUNTIFS('Order List'!C:C,F$1,'Order List'!AG:AG,"*Orange*")
This works.
Now I want to know how many orders include bananas and/or oranges.
The sum of the 2 previous results does not work, since any order including both Oranges and Bananas would be counted twice.
I could not find a way to write the regular expression that matches the case where both appears (to subtract the intersection), because 1) there is no ordering in the list, so banana could appear before or after orange and 2) because the number of intersections grows too fast when more items are in the list.
It seems a simple problem but I haven't figured out how to do this, your help is very much appreciated !
You may try:
Formula in C1:
=SUMPRODUCT(--(MMULT(IFERROR(FIND(TRANSPOSE(B1:B2),A1:A5),0),MOD(ROW(A1:INDEX(A:A,COUNTA(B1:B2))),1)+1)>0))
I think you'll need to CSE-enter this pre-Excel365.
You can apply a trick. First SUM both individual result then substract result counting contains both. Like below-
=COUNTIF(B3:B6,"*Banana*")+COUNTIF(B3:B6,"*Orange*")-COUNTIFS(B3:B6,"*Banana*",B3:B6,"*Orange*")

Two or more identical parameters in one sentence

I have a dialogflow intent which includes different parameters.Shown as below:
1.png
I set generic "number" for all number parameters such as "Years to Average Principal" and generic "percentage" for all percentage parameters.Like this:
2.png
When I say something like "Change vacancy rate to 56%" or "change Years to Average Principal to 5", it works well.But when I say a sentence which includes two or more parameters with same type, it sets the first value for all parameters.I used the "Change depreciation percentage to 30% and down payment to 45%" phrase and the result is following images:
3.png
4.png
As I have to use only one intent and one action,would you please help me what should I do to have separate values for different parameters?
I hope I could make it clear. Thanks in advance,
Good try using the "is list" setting for a parameter! Unfortunately, you only set it for one of the parameters, so it treated that as the list and then used the first matching value for the other parameters since both matched the rule for percentage. If one was for percentage and the other for currency, it might have worked better, but probably not.
Two (untested) thoughts about how to get this to work (and it is a good attempt to solve the problem of entering multiple values at a time):
You can try to see if setting all the other parameters as lists will work as well. But this still might have the problem of setting one parameter to a number and the other to a percentage.
Look into Developer Composite Entities. This will let you create a composite entity that contains both the name and value and treat it as a single Entity. Then you can specify, in your sample phrase, that you will accept a list of these Entities.

Most Common Value within Sublists

I apologize in advance if this is unclear, I will try to explain everything as best I can! I am working with a data set in Google Sheets such that Column A is a list of student IDs and Column B is a list of student behaviors. It looks something like this:
A(ID) B(Behaviors)
12345 Talking
54321 Out of Seat
98765 Lying
12345 Talking
12345 Lying
98765 Lying
The list is data set is quite large because it contains recorded data from the entire school population over the course of the year, and as you can see the entire student population is pooled in one list. I am looking for a way to find each students (identified by their IDs) most commonly assigned behavior. For example, for the above data, student 12345 would have 'Talking' listed as their most common behavior and student 98765 would have 'Lying' listed as their most common behavior.
Ideally, I want to create a separate spreadsheet that looks something like this:
A(ID) B(Most Common Behavior)
12345 Talking
98765 Lying
54321 Out of Seat
Such that column A is a list of all the student's IDs and column B lists their most common behavior.
I found that I could use this formula:
=INDEX(Behaviors,MODE(MATCH(Behaviors,Behaviors,0)))
To pull out the most common value from the column containing scholar behaviors, but this formula gives me the most common behavior among the entire student population, so I am interested in modifying it so that the formula first looks at the student ID and then looks at the most common behavior within that sublist.
Please let me know if you require any further information. Thanks in advance for your help!
Are you familiar using PivotTables? You could just create a PivotTable with ID as a Row Label and Behavior as a column label and Value. Then it would just be a matter of copying/pasting those values and using a MAX formula to get the greatest behavior count.

Can't get INDEX/MATCH functions to do what I need?

It is quite an in depth excel sheet (to me) so here is a link to it: https://dl.dropboxusercontent.com/u/19122839/Movies.xlsm
On the Filters sheet, I have a search feature. This allows you to put in different genres, years, etc. and will pull up results.
The genre part does not seem to be working correctly for some reason.
In the movie_genres sheet, there is a Genre Equals and Genre Count column that seem to be marking the information correctly, but when you go to the movies sheet, the Matches Genre column does not. I use this function:
=INDEX(Genres[Genre Count],MATCH(Movies[[#This Row],[ID]],Genres[ID],0))
Which, to me, should pull the Genre Count, but in the case where there are more than one genre (I used Blank Check as an example in this case), it doesn't mark it as a 1. How can I make it so that this gets corrected.
For example, if you add the Comedy as a second genre, it pulls up more results than if you only have Family. I think I just need a fresh pair of eyes looking at this and it is probably something dumb, but any help would be great.
I believe I need to make it so that the index/match function I use in Movies[Matches Genre] will work as long as there is a 1 in Genres[Genre Count] for that ID. It only seems to work if there is a 1 in the first instance of the ID.
EDIT: I have added in a COUNT feature to better explain what I am talking about. With only Family as a genre, it shows there are 10 results, but when you add Comedy as a second genre, you get 40 results. This number should never go up as you add genres.
Perhaps try using SUMIF like this
=SUMIF(Genres[ID],[#ID],Genres[Genre Count])
If one movie might have several 1s but you only want 1 maximum then change to
=IF(SUMIF(Genres[ID],[#ID],Genres[Genre Count])>0,1,0)

Resources