Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 14 Next »

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: .

The Parameter table entry should look as follows:

Note that the parameter name, by convention, is completely in lower case. This is important to realize as it is the parameter name that is received from Dialogflow and filters stored in the conversational memory of the agent will be of the form dietaryrestriction='vegan', for example. In your Prolog code (see below), therefore, you need to use the all lower case label! As there can be more dietary restrictions that a user might add simultaneously, the box in the IS LIST column is checked. Check out the entity to see what kind of dietary restrictions have been added.

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

recipe_selection.pl

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

diet

diet(RecipeID, DietaryRestriction) :-

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’. diet should work if the list of ingredients of the inputted RecipeID fits the dietary restriction inputted DietaryRestriction.

ingredientsMeetDiet([ Ingredient | Rest ], DietaryRestriction) :-

The ingredientsMeetDiet predicate 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. 

Make an applyFilter function for it

Predicate to filter recipes that meet the dietary restrictions (such as ‘vegan’).

applyFilter('dietaryrestriction', Value, RecipeIDsIn, RecipeIDsOut) :-

  • This rule should filter recipes based on their membership to dietary restriction. To check if a recipe is a member of a dietary restriction you can use the built-in Prolog member/2 predicate.

  • (member(Recipe, List of Recipes),

  • diet(Recipe, Dietary Restriction))

Extending the logic of ingredient hierarchies

Add the following predicate above hasIngredient in ingredient_hierarchies.pl file.

typeIngredient(Ingredient, 'vegan') :-
	not(typeIngredient(Ingredient, 'non-vegan')), !.

Add to the ingredient hierarchy by adding ingredient type functions and type ingredient lists to include vegetarian, lactose-free, gluten-free, and pescatarian dietary restrictions

Here is an example of a typeIngredient rule:

typeIngredient(Ingredient, 'gluten-free') :-
	not(typeIngredient(Ingredient, 'gluten')), !.

Here is an example of the type of ingredient lists

 typeIngredient(Ingredient, 'gluten').

typeIngredient('barley squashes', 'gluten').
typeIngredient('beer', 'gluten').
typeIngredient('lager', 'gluten').
typeIngredient('stout', 'gluten').
typeIngredient('stout', 'gluten').
typeIngredient('barley', 'gluten').
typeIngredient('couscous', 'gluten').
typeIngredient('bulgar wheat', 'gluten').
typeIngredient('dinkel', 'gluten').
typeIngredient('einkorn', 'gluten').
typeIngredient('emmer wheat', 'gluten').
typeIngredient('farro', 'gluten').
typeIngredient('freekeh', 'gluten').
typeIngredient('khorasan wheat', 'gluten').
typeIngredient('pearl barley', 'gluten').
typeIngredient('rye', 'gluten').
typeIngredient('semolina', 'gluten').
typeIngredient('spelt', 'gluten').
typeIngredient('triticale', 'gluten').
typeIngredient('wheat', 'gluten').
typeIngredient('wheat flour', 'gluten').
typeIngredient('rye flour', 'gluten').
typeIngredient('barley flour', 'gluten').
typeIngredient('plain flour', 'gluten').
typeIngredient('self raising flour', 'gluten').
typeIngredient('flour', 'gluten').
typeIngredient('oats', 'gluten').
typeIngredient('oat milk', 'gluten').
typeIngredient('biscuits', 'gluten').
typeIngredient('bread', 'gluten').
typeIngredient('cake', 'gluten').
typeIngredient('chapattis', 'gluten').
typeIngredient('crackers', 'gluten').
typeIngredient('muffins', 'gluten').
typeIngredient('pastry', 'gluten').
typeIngredient('pizza', 'gluten').
typeIngredient('muesli', 'gluten').
typeIngredient('pasta', 'gluten').
typeIngredient('noodles', 'gluten').
typeIngredient('batter', 'gluten').
typeIngredient('soy sauce', 'gluten').
typeIngredient('liquorice', 'gluten').
typeIngredient('bread crumbs', 'gluten').

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.

Test it Out

Try to ask your conversational agent to add dietary restrictions for, for example, vegan recipes. Try various types of restrictions to see how that works. What can you say about how consistent the logic that is defined for these restrictions is? You may want to think about how to improve that (and, if you have any ideas that you did not implement, reflect on that in your report, for example).

  • No labels