next up previous contents
Next: Rules Up: Unit 3: Prolog: queries Previous: Unit 3: Prolog: queries

Querying facts

The following database represents a simple recipe for making a vinaigrette sauce, formulated as Prolog facts.

ingredient(vinaigrette,vinegar).
ingredient(vinaigrette,oil).
ingredient(vinaigrette,salt).
ingredient(vinaigrette,pepper).
ingredient(vinaigrette,mustard).
mix(vinaigrette,salt,pepper,mixture1,by_shaking).
mix(vinaigrette,mustard,mixture1,mixture2,by_stirring).
mix(vinaigrette,vinegar,mixture2,mixture3,by_stirring).
mix(vinaigrette,oil,mixture3,mixture4,by_stirring_dropwise).

Queries to the database might be of various kinds:

The second technique, using variables, permits very flexible database querying, in which one or indeed all possible correct matches can be found. Query results such as the following can be achieved:

ingredient(vinaigrette,mustard). yes
ingredient(vinaigrette,What). vinegar oil salt pepper mustard
ingredient(Recipe,mustard). vinaigrette
mix(A,B,C,D,Mix_Styles). by_shaking by_shaking by_stirring by_stirring by_stirring_dropwise


Dafydd Gibbon
Thu Feb 12 11:04:00 MET 1998