Comparing two sets of instances in a query



I was wondering whether it’s possible to compare two sets of individuals to determine whether one set contains the other using a get query.

To make it a bit more specific:

Suppose I have some recipes that require different ingredients and a pantry with a set of available ingredients. I have modeled the connection between a recipe and its required ingredients as a relationship: (requiring_recipe: $r, required_ingredient: $i) isa requires, where $r and $i are entities of types recipe and ingredient respectively. And the connection between the pantry and the ingredients is modeled as a relationship as well: (containing_pantry: $p, contained_ingredient: $i) isa contains, where $p and $i are entities of types pantry and ingredient respectively. Now I would like to query the data to find out which recipes I could cook with the ingredients that are available in the pantry. I thought that the following query would give me the answer:
match $p isa pantry; $ip isa ingredient; (containing_pantry: $p, contained_ingredient: $ip) isa contains; $r isa recipe; (requiring_recipe: $r, required_ingredient: $ip) isa requires; get $r;
But this query gives too many results, probably because it returns the recipes that require at least one of the ingredients in the pantry, but also require ingredients that are not available. So I was wondering how to query the data such that the query returns only those recipes for which the set of required ingredients is contained within the set of available ingredients.



It might not be possible with the current release.
However! The next release -1.5, to be out by the end of the month - should be equipped with pattern negation.

Then your query Q($r) - recipes with all ingredients being available (in the pantry) can be understood as:

Recipes with no ingredients we don’t have (in the pantry).

Hence we can have:

available-ingredient($i) :- contains($p, $i) 
recipe-with-unavailable-ingredient($r) :- recipe($r), requires($r, $i), NOT available-ingredient($i)


Q($r) :- recipe($r), NOT recipe-with-unavailable-ingredient($r)

The release is still in development and we are fleshing out the syntax so bear with us. I will try to update this post when ready.


Thanks for your reply!
Looking forward to the 1.5 release!