...
It is not necessary to add phrases that are completely unrelated to the topic of our recipe recommendation agent, as these would definitely come back as an unknown intent. Thus, what you should do is think of related phrases that would be close to an intent but should not match with it. For example, “I do not like mushrooms” is food related and refers to an ingredient entity ‘mushroom’. Yet, you might argue that it should not be matched to any of the intents you specify , because you do not want users to discuss their likes and dislikes with your agent. Alternatively, you could also argue to include ‘I like’ and ‘I dislike’ as training phrases for filtering by something. But that is a design decision for you to make! The Fallback Intent should be updated as you add more intents throughout the project.
...
Before you can continue creating intents, you have to create the entities you need, since these will be part of the intent specification for certain entities (e.g., the presence of an entity type is used as a feature by the Dialogflow classifier model to recognize certain intents by). Some of these entities have already been provided to you. For information on how to upload and create entities, please read this page: DialogFlow: Create an Agent, Intents and Entities.
Some entities have not been provided with the agent project. You have to add them yourself (see the list below). We provide an example for most to make sure you have at least a few entries for each entity. They may not be that intuitive at first, so make sure to extend the entity specification with more synonyms as you develop your agent evolvesfurther.
Note |
---|
If the word you enter for an entity entry has synonyms, enter these as synonyms rather than adding these as different entity entries! |
removeKeyword - words to remove filters (for example ‘remove’)
timeKeyWord - words that refer to measurements of time (hour, minutes, etc.)
shortTimeKeyWord - for example ‘fast’, ‘quick’ etc.negationKeyword - to specify that something needs to be omitted (for example ‘without’ or ‘don’t’)
easyKeyWord - to specify recipes that are not hard to make (for example ‘simple’)
When you are done your entities Entities page should look as followshave the following entities:
...
The ‘addFilter’ Intent
The intent for filtering recipes is one of the most important intents. It is used to filter recipes for the user based on a variety of criteria. This is the first intent that employs all the entities we have created. In the user expressions, where the user is asking to filter, all different entities need to occur and be tagged in the set of examples. For example, for a training phrase like “I want a Chinese recipe”, ‘Chinese' needs to be tagged as ‘cuisine’, so this phrase can be parsed by Dialogflow in order to apply the filter ‘cuisine’ to the recipes in our database. The ‘addFilter’ intent can be found in the folder project provided to you , to start with and should be uploaded in Dialogflow by you.
...
To filter the recipes for the user in the way they intend, their utterances are mapped onto the intents and entities you specified in Dialogflow. This then returns the identified intent (for example, ‘addFilter’) and entity information (for example, cuisine - ‘Chinese’). The MARBEL agent must be able to use this information. In order to make this happen, you need to create Prolog rules to filter the available recipes in the Prolog database. This can be done by introducing the following Prolog predicates. We have already specified the heads of all rules in the recipe_selection.pl
file. That is where you still need to add the bodies for these rules. We need a few helper functions before we can start implementing code for filtering, which are described next. For each rule, you first need to uncomment it.
nrOfIngredients
We will start off easy.
Code Block |
---|
nrOfIngredients(RecipeID, N) :- |
Create a rule to return N
, the length of the list of ingredients for a certain RecipeID
. HINT Hint: your Visual Support groupmates team members should have made an ingredients function that could help.
nrSteps
Code Block |
---|
nrSteps(RecipeID, N) :- |
Create a rule to return N
, the number of steps for a certain RecipeID. HINT: your groupmates should have made a recipeSteps function that could help.
...
In the diet rule, we need to find all the ingredients that a certain recipe has and then input them into a new function we shall create below diet, called ‘ingredientsMeetDiet’. This function should return a diet should work if the list of ingredients that fit of the inputted RecipeID fits the dietary restriction . This list should be returned with the name inputted DietaryRestriction.
Code Block |
---|
ingredientsMeetDiet([ Ingredient | Rest ], DietaryRestriction) :- |
The ingredientsMeetDiet predicate is our stop clause, which should take a list of ingredients and check if each one meets a dietary restriction. It has a stop clause that is in the file already and will recursively check each ingredient and return ‘false’ when an ingredient does not meet the given dietary restriction. The predicate ‘typeIngredient’ can be used to check if an ingredient meets a dietary restriction. Fill in the body of the rule for ingredientsMeetDiet.
...
There are a number of different rules that you need to implement for the applyFilter/4
predicate, depending on the specific filter that needs to be applied. For example, filtering recipes for a cuisine asks for a different rule than filtering for the duration of a recipe. These variants are specified in the table below. For each rule, you first need to uncomment it.
applyFilter
Code Block |
---|
applyFilter(+ParamName, +Value, +RecipeIDs, -FilteredRecipes) |
...
Predicate Description | Rule Head | Notes/Instructions |
---|---|---|
The predicate to filter recipes on cuisines (e.g., Italian recipes) | applyFilter('cuisine', Value, RecipeIDsIn, RecipeIDsOut) :- |
|
Predicate to filter recipes that meet the dietary restrictions (such as ‘vegetarian’). | applyFilter('dietaryrestriction', Value, RecipeIDsIn, RecipeIDsOut) :- |
|
Predicate to filter recipes on the max amount of time | applyFilter('duration', Minutes, RecipeIDsIn, RecipeIDsOut) :- |
|
Predicate to filter easy recipes | applyFilter('easykeyword', _, RecipeIDsIn, RecipeIDsOut) :- |
|
Predicate to filter recipes on the exclusion of a specific ingredient | applyFilter('excludeingredient', Ingredient, RecipeIDsIn, RecipeIDsOut) :- |
|
Predicate to filter recipes on the exclusion of a specific ingredient type (for example: ‘beef’) | applyFilter('excludeingredienttype', Ingredient, RecipeIDsIn, RecipeIDsOut) :- |
|
Predicates to filter recipes on a specific ingredient inclusion | applyFilter('ingredient', Ingredient, RecipeIDsIn, RecipeIDsOut) :- |
|
Predicate to filter by including an ingredient type | applyFilter('ingredienttype', Ingredient, RecipeIDsIn, RecipeIDsOut) :- |
|
Predicate to filter recipes on meal type (for example: breakfast) | applyFilter('mealType', Value, RecipeIDsIn, RecipeIDsOut) :- |
|
Predicate to filter recipes on a maximum number of ingredients | applyFilter('nrOfIngredients', Value, RecipeIDsIn, RecipeIDsOut) :- |
|
Predicate to filter recipes on a maximum number of steps | applyFilter('nrSteps', Value, RecipeIDsIn, RecipeIDsOut) :- |
|
Predicate to filter recipes and return fast recipes. A recipe is fast if it takes less than 30 minutes | applyFilter('shorttimekeyword', _, RecipeIDsIn, RecipeIDsOut) :- |
|
Predicate to filter on the number of servings | applyFilter('servings', Value, RecipeIDsIn, RecipeIDsOut) :- |
|
Predicate to filter recipes on a tag (for example: pizza) | applyFilter('tag', Value, RecipeIDsIn, RecipeIDsOut) :- |
|
...
‘deleteFilterValue’ is useful to deal with a scenario where the user requests to remove a filter that they have already put on specifically. For example, “I wish to remove the onion filter”, “Forget about excluding broccoli”, and “Can you delete the Chinese cuisine”. . Add some training phrases with all the different filters that could be deleted.
It is thus important that in your training phrases, you include a variety of all filter-related entities and that these entities are also given specific values and parameter names in the Action and Parameters tables. These entities are given new parameters and value names in order to identify them as a filter to be deleted. Specifically, you tag the entity in your training phrases as normal and then you change the parameter name and value name to “entitynameDel”. Your entity table under Action and Parameters should look like this when you are done.
...