Table of Contents | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Including ingredients, meal types, cuisines
Prolog and Patterns
We need to refine our logic now for retrieving only those recipes that satisfy specific filters. We already introduced a recipeFiltered/3
predicate for [TBU]Request a Recommendation but there it did not have to do any serious work yet. We only introduced the base case without any filters (an empty list of filters) but now need to deal with the case where we have some filters that a user provided. The basic idea to define a recursive clause for recipeFiltered/3
is simple: apply the first filter in the list to the recipes and recursively filter the remaining recipes using the remaining filters. We provide you below with the recursive clause that you should add below the base clause that we added earlier in the recipe_selection.pl
file:
...
If we want to check that a recipe uses an ingredient, we need to be able to check whether the ingredient is included in the ingredient list of that recipe. For ingredient types, things are slightly more complicated. To do both checks, we will add two rules for defining the need a rule, hasIngredient(RecipeID, Ingr)
. The hasIngredient(RecipeID, Ingr)
predicate that rule should succeed if the recipe with identifier RecipeID
uses the ingredient(type) Ingr
. The first Prolog rule for hasIngredient
is designed to determine if a specific ingredient is used in a given recipe. It simply checks if Ingr
is included in the ingredient list of recipe RecipeID
by using the ingredient/2
predicate (see the recipe_database.pl
file).
The bodies of the rules can be designed as exact copies of each other. You must find all (Hint for what Prolog built-in predicate you should use) recipes from the list that you start with that satisfy the filter and return these recipes in the output argument list. Add your rules to the recipe_selection.pl
file at the location indicated in the file; there you will also find the heads of the rules that you need to define. The rule for filtering on cuisine is very similar too but instead of the hasIngredient/2
predicate you should use the cuisine/2
predicate (see the recipe_database.pl
for examples).
...
For the featureRemovalRequest
intent, you should add a simple text/2
fact. Use as response text, for example, "Can you have a look again and remove one of your recipe requirements?".
Visuals
We want to differentiate what we show to a user depending on the number of recipes that still meet the user’s requests. The basic idea is that we should not show a large number of recipes to a user but we can show recipe details when the number of remaining recipes becomes sufficiently small (we chose <16, see also above). As a consequence, we want to create two different versions of the a50recipeSelect
page that we created for https://socialrobotics.atlassian.net/wiki/pages/createpage.action?spaceKey=PM2&title=2025%20Capability%202%3A%20Request%20a%20Recommendation: one that just shows the feature requests made when there are more than 15 recipes that meet these requests, and another for when there are less that 16 which shows the recipe details (titles and pictures) for all of the remaining recipes.
...