Table of Contents | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Dialogflow
Entity for number of ingredients and number of recipe steps
...
Another way to improve your Dialogflow agent is to enable a user to include multiple requests in a single user expression. You can achieve this simply by including many more phrases such as “I’d like a Chinese recipe with less than 8 ingredients”. This will ensure that your conversational agent can recognize multiple filter requests.
Prolog and Patterns
Retrieving the (number of) ingredients and recipe steps
...
Now add a similar rule that applies a filter for the nrOfSteps feature; your Training phrases should dictate how to read the constraint. I.e., if your phrase says “less than N recipe steps” than you should write code that implements the filter to mean exactly that.
Add a similar rule that applies a filter for the servings feature. You probably want to make sure that a recipe has exactly the right number of servings that the user asked for.
Finally, add a rule that applies a filter for the duration feature. This feature is a bit more tricky and you should take the warning above about data types to heart. However, most of the work has already been done for you in the
dialog_update.mod2g
file in a step called Pre-process parameters of intent. In this step, the duration values received from Dialogflow are transformed to minutes (numbers) using theduration_to_min
predicate defined in theutils.pl
file. This means that to define the rule for filtering, you simply need to look up the time it takes to cook a recipe in the database (specified in minutes), and compare that value with the maximum duration that the user specified.
Visuals
Extend the recipe confirmation page
The You should extend the initial version of the recipe confirmation page that we created for Capability 2: Request a Recommendation should be extended now and also show the recipe instruction and ingredient details now. The main requirement is that the page now also will show the recipe instructions, the ingredient list with quantities, the duration, and number of servings. Use the Prolog rules you created for recipeStepssteps(RecipeID, StepsListStepList)
and ingredients(RecipeID, IngredientList)
to retrieve these the first two from the recipe database . Then add these to two new cards that you add to the page for showing these recipe details.
Retrieve the following information by putting the appropriate predicates in the places indicated in the rule by comments and by using the variable names indicated below.
We need to retrieve the chosen recipe from memory. Find the necessary predicate and name that variable ‘Recipe’.
The previous step retrieves the Recipe ID, but we also need the recipe name. Use a variable called ‘Name’ for this.
Retrieve the time needed to complete the recipe in a variable named ‘Minutes’.
Retrieve the number of servings in a variable called ‘Persons’.
To retrieve a list of the recipe steps and a list of ingredients, you will need two additional predicates in
recipe_selection.pl
.The first of the two predicates is a rule that returns a list of ingredients
ingredients(RecipeID, IngredientList) :-
Implement a rule in
recipe_selection.pl
calledrecipeSteps(RecipeID, StepsList) :-
to retrieve a list of the recipe steps without changing their order. There is no repetition, so this predicate does not need to remove duplicates. Your rule for retrieving the steps needs to use the accompanying rule given belowgetStepString
in your goal of the built-in Prolog predicate, so your goal should look as follows:RecipeID^getStepString(RecipeID, Step)
.Code Block getStepString(RecipeID, String) :- step(RecipeID, NrStep, StepSentence), to_upper_case(StepSentence, StepSentenceUpper), atomic_list_concat(['Step ', NrStep, ': ', StepSentenceUpper], String). %, '.'
Go back to
html.pl
and toa50recipeConfirm
Save the recipe steps as ‘Steps’
Save the list of ingredients as ‘Ingredients’
Ask for recipes with 5 ingredients and see if you receive the following answer.
...
Test it Out
Check if the recipe on the a50recipeConfirm
page fulfills the criteria you chose and the time/2
and servings/2
predicates for the last two. Add the duration and servings to the card that already was created for this page. Add two new https://www.w3schools.com/bootstrap4/bootstrap_cards.asp to the page for showing the recipe instructions and list of ingredients. You may also want to add the feature requests to the recipe confirmation page, but we leave this design choice up to you. You definitely may want to put more work in the styling of the content and the layout of this page to make it look appealing.
Test it Out
Make sure to test that all filters introduced for this capability work. To test the new filters, ask, for example, for recipes with less than 5 ingredients and check whether you see the following:
...
For the recipe confirmation page, check if the recipe on that page fulfills the feature requests you made for the number of steps, number of servings, and duration. Make sure to test that all filters introduced for this capability work, which should be shown on that page.
Info |
---|
All done? |