rasa-core Map entities to other entites - rasa-core

I am building a simple food ordering bot. In this I have a take_order intent in which two entities will be extracted food_item and quantity, both of these entities have list types in slots, for example if a user message like this comes:
I would like to have [one] (quantity) [chicken burger] (food_item) and [two] (quantity) [fries] (food_item)
slot for this example will be: slot{“quantity”: [“one”, “two”], “food_item”: [“chicken burger”, “fries”]}
in the action user_take_order I will be multiplying quantity of each item to its price and giving total bill to the user.
But I have a problem, in a complex case when user do not provide a quantity for the food_item, I will be assuming the default quantity to one but the problem occurs when user orders three items and do not provide quantity for only the second item, for example:
I would like to have [one] (quantity) [chicken burger] (food_item), [fries] (food_item) and [two] (quantity) [soft drinks] (food_item)
in this example no quantity is provided for the fries and slots filled: slot{“quantity”: [“one”, “two”], “food_item”: [“chicken burger”, “fries”, “cold drink”]}
in the action user_take_order I would like to do this:
1 x price_of_chicken_burger
1 x price_of_fries
2 x price_of_cold_drink
but the problem is that in quantity slot I have only quantities of chicken burger and cold drink and I do not have a clue that user did not mention the quantity of fries( I want to set quantity of fries as 1 “default case”)
have I choose the wrong types for slots quantity and food_item?
slots:
food_item:
type: list
quantity:
type: list

One of the possible solutions is to extract quantity and food item as one entity:
I would like to have [one chicken burger] (quantity_food_item), [fries] (quantity_food_item) and [two soft drinks] (quantity_food_item)
then differentiate them inside an action.

Related

Validation list with multiple criterias

I sort out my problem but I am wondering if an easier way doing it doesn't exist.
With the function onEdit(), I am creating from a first validation list, a second validation list in the next cell.
So, the code below is just for information.
var validationRange = data.getRange(3, myIndex, data.getLastRow());
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).build();
activeCell.offset(0, 1).setDataValidation(validationRule);
In this validation list, I need to select a name, taking into account two additionnal criterias :
Name
Times
LastWeek
Patrick
2
W22
Rachel
5
W15
Claire
3
W14
Olivier
4
W16
Hélene
2
W20
It means that "Patrick" attended "2" times and last time was in week "W22".
I need to take into account these two criterias to select one of the attendee
I.E. : I try to let each person participate the same number of times but not every week (the oldest first)
So, I created a validation list with a "sorted key" that allows me to first see the person who has attended less and for longer.
Key Sorted
#02W20#Hélene
#02W22#Patrick
#03W14#Claire
#04W16#Olivier
#05W15#Rachel
This validation list is used 3, 5, 7 times in the same sheet because person can do different activities. Then, when all person are selected another script removes the values between # to keep only the name in the final sheet.
So, the question is :
could we create a validation list with multiple columns, the selected value being only the value of the first column.
I guess many users would enjoy it when we glance at questions about multiple criteras selection lists.
Thanks

Calculate percentage when an item can be assigned to multiple categories

this might be a stupid question but I'm blanking at the moment and can't find the answer in google.
I have the following example table
customer
bought
A
food
B
food,drink
C
drink
D
drink
now how do I calculate the percentage of customers that bought food/drink over total customers? what would be the best way to calculate this?
solution
% food = #customers who bought food / #total unique customers = 2 / 4 = 50%
% drink = #customers who bought drink / #total unique customers = 3 / 4 = 75%
the problem here is the total % exceeds 100%
solution - count customer B twice, once for drink and once for food
% food = #customers who bought food / #total customers = 2 / 5 = 40%
% drink = #customers who bought drink / #total customers = 3 / 5 = 60%
the total is 100% but is this the correct way to calc % in this case?
The issue is obviously that one customer can buy both food and drink and I'm not sure how to handle this case. Any help would be appreciated. Thank you!
UPDATE:
thanks for the answer. It makes sense to remove altogether the customers who bought both products. But now I'm wondering what happens if there are more than 2 categories?
Example as follows, now we have an additional product (ice cream) in the mix
customer
bought
A
food
B
food,drink
C
drink
D
drink
E
drink,ice cream
F
ice cream
G
food,drink,ice cream
I guess with the same logic we can remove customer G since they bought all the products? And how should we handle customer E and B?
I think that what you are looking for is simply to eliminate the number of customers that purchased both products.
If you are looking for unique combinations of customers who purchased only a specific product then:
3 unique customers bought a single unique item
1/3 food => 33%
2/3 drink => 66%
The ones who bought both products, don't matter in these calculations since they add the same percentage to both cases.
EDIT:
I used excel to help me out. I hope that is fine
I added your data into an excel sheet and created a crosstable pivot.
I've set the Customers as columns and the Products as rows, in order to see what each individual customer has purchased via the values field Count of Product
I've changed the count of Product into the formula for % of Total
in order to show me for each product, the percentage split between the customers, so for example if customer B bought both drink and food he will be shown as 50% in both corresponding rows. If he bought all 3 then 33%
The grand total column, will contains the final percentage for each product row item. Excel calculates it the same way as states in some comments, it counts the products total instead of the customers total, which makes sense since that is your data set being consumed, and not the customers themselves.
If we swap the rows and columns around and do the same calculations, we see individual percentages for each customer (how much % of product they each individually purchased) and we can sum them up for each product. The result is the same

Right algorithm for grouping food items and ingredients?

Problem
Given N food items each containing a set of ingredients. There are a pool of M ingredients.
A group is formed consisting of food items and ingredients such that each of the food item in that group contains all of the ingredients in that group.
The problem is to create the groups using the foods and ingredients such that each ingredient and a food item is covered(There should be a group present corresponding to each mapping of food item and ingredient) with the constraint of minimising the number of groups created.
Example:
Input
N = 3, M = 3
Ingredients('a', 'b', 'c')
Food Item 1 containing ('a', 'b', 'c') ingredients.
Food Item 2 containing ('b', 'a') ingredients.
Food Item 3 containing ('a', 'b', 'c') ingredients.
Output
2 groups
Group 1: (Food Item 1, Food Item 2, Food Item 3)('a', 'b')
Group 2: (Food Item 1, Food Item 2)('c')
The solution that I thought of is to compute all subsequences of the ingredients, assign them to groups and add the appropriate food items in the group. But, this doesn't seem to be the right algorithm.
I think I can help with this, but it's not clear in your question what is "minimizing" for you and also what "..is covered" means for you.
In you example, if you considered only the first 2 groups that is
Food Item 1
Food Item 2
it seems that all food items are covered, and also all the ingredients , 'a'+'b' being in the first group and 'c' being in the second group. What am I missing here that you added the third group?
Thanks,
The easiest approach would be:
create a Group for every single ingredient.
put in these groups all Food items that contain that ingredient.
check if two different Groups contain the same Food items, join them together.
repeat until there are no two Groups that contain exactly same Food items.

Solving a logic puzzle via Prolog

So I have a knowledge base of these three tables
% order(customer_name, item_name, quantity).
% customer(name, credit_rating).
% item(name, quantity_in_stock).
I am supposed to find all valid orders. Valid orders are defined as valid customers with a good credit rating (rating above 500), the item the customer is ordering should exist in the stock and the order quantity must be less than that of the quantity_in_stock.
I already figured out for good rating, its just customer(X, Rating), Rating >=500. But I cannot figure out how to combine a good customer rating, quantity and then comparing that to the quantity_in_stock.

Complicated Cube Query

I'm working on a fairly complicated view, which calculates the total cost of a guest's stayed based on data pulled from four different tables. The output however is not exactly what I want. My code is
CREATE OR REPLACE VIEW Price AS
SELECT UNIQUE
Booking.Booking_ID AS "Booking",
Booking.GuestID AS "Guest ID",
Room.Room_Price*(Booking.CheckOutDate-Booking.CheckInDate) AS "Room Price",
Add_Ons.Price AS "Add ons Price",
Room.Room_Price*(Booking.CheckOutDate-Booking.CheckInDate) + (Add_Ons.Price) AS "Total Price"
FROM Booking JOIN Room ON Room.Room_Num = Booking.Room_Num
JOIN Booking_Add_Ons ON Booking.Booking_ID = Booking_Add_Ons.Booking_ID
JOIN Add_ons ON Booking_Add_Ons.Add_On_ID = Add_Ons.Add_On_ID
ORDER BY Booking.Booking_ID;
Now, I'm trying to get this to return the total cost of all Addons, plus the cost of the hotel rooms as the total price, however it is returning the cost of the rooms + each of the addons on separate lines. As follows:
My question is, is it possible to use something like CUBE, or SUM to add up the rows, so that there is only one entry for each of the Bookings with the total price of all add-ons accounted for?

Resources