Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents
minLevel1
maxLevel2
outlinefalse
typelist
printablefalse

Dialogflow

Entity for number of ingredients and number of recipe steps

...

In a similar vein, you should add phrases about the number of recipe instruction steps such as “I’m looking for a recipe with less than 8 steps”, and the number of servings of a recipe. Use as parameter names nrOfSteps nrSteps and servings. This will make sure the MARBEL agent will receive filters of the form nrOfStepsnrSteps=8 and servings=4 and store that in its conversational memory. Finally, also annotate for recipe duration for a parameter called duration but instead of @sys.number use the @sys.duration system entity of Dialogflow.

...

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

...

Using the rules for ingredients/2 and steps/2, you should now be able to define rules for nrOfIngredients(RecipeID, N) and nrOfStepsnrSteps(RecipeID, N) that return the number of ingredients and instruction steps, respectively, by computing the length of the list of ingredients and steps.

...

Note

It is very important to make sure that values are of the right type. The values that Dialogflow returns are often atoms or strings. Comparing strings to numbers using the < operator, for example, will result in a Type error in SWI Prolog that will terminate the MARBEL agent.

To avoid such issues, we therefore always need to make sure that values that must be numbers (because they match with @sys.number entity type in Dialogflow) are converted to numbers again in Prolog. There are predicates defined for this purpose in the utils.pl file. For the duration, time(?ID:atom, ?Time:integer) already transforms the duration into minutes, so no additional transformation is necessary.

  • Now add a similar rule that applies a filter for the nrOfSteps nrSteps 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 the duration_to_min predicate defined in the utils.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

You should extend the initial version of the recipe confirmation page that we created for Capability 2: Request a Recommendation 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 steps(RecipeID, StepList) and ingredients(RecipeID, IngredientList) to retrieve the first two from the recipe database 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.

...