Versions Compared

Key

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

The next thing we want to add is the capability to filter on dietary restrictions. This will require extensions to your Dialogflow agent for NLU but also require the implementation of new logic in Prolog for filtering the recipe database on these restrictions.

Dialogflow

As a first step, use the following CSV file to upload the dietaryRestiction entity:

View file
namedietaryRestriction.csv
.

...

To make your Dialogflow agent extract this entity, you again need to add more training phrases, and annotate these phrases for the dietaryRestrction entity, and extend the addFilter intent with these phrases. You can use the test console of your agent to verify that it is able to recognize addFilter intents with dietary restrictions and extract the entity entries you just added.

Prolog and Patterns

In the previous capabilities that we implemented for filtering the recipe database, we often could simply use the facts that are part of that database to implement the filtering process (the applyFilter/4 rules). For example, for Capability 5: Filter Recipes by Ingredients and Cuisine we could use the ingredient/2 and cuisine/2 facts, and for Capability 6: Filter by Number of Ingredients & Recipe Steps, we could use time/2 for the cooking duration of a recipe and servings/2 for the number of servings. For computing the number of ingredients and recipe instructions steps, we had to do a bit more work, but these could also be computed quite straightforwardly from these basic facts.

We have only seen one other example so far of a feature request that could not be implemented by using basic facts from the recipe database: the ingredient type for Capability 5: Filter Recipes by Ingredients and Cuisine. When you inspect the recipe_database.pl file, you will see that there are also no simple facts in the database that suggest that a recipe is vegan or spicy, for example (two restrictions that are included in the dietaryRestrction entity in the Dialogflow agent). We need to add some logic to enable the agent to conclude from the basic knowledge stored in the database about a recipe that is satisfies a dietary restriction.

Filtering on dietary restrictions

The basic idea to implement the logic for checking a dietary restriction is to check whether each ingredient of a recipe meets that dietary restriction. It is clear, for example, that a recipe that uses chicken, is not a vegetarian recipe. The reasoning is simple: Vegetarians do not eat any kind of meat, chicken is a kind of meat, so any recipe that uses chicken is not a vegetarian recipe. If we can retrieve this information about chicken somehow, then we can implement this logic for our agent too.

First, begin by adding some supporting predicates to the recipe_selection.pl file.

...

We recommend using automated approaches to compile these lists.

Visuals

Nothing we ask you to do here for this capability. It’s up to you.

...