Rules

Rules are the basis for more interesting statements about a domain, and for more complex reasoning. In our family.flr ontology, we use child as a primitive relationship, which has to be explicitly asserted. We also assert the gender of each individual. All other family relationships are then derived based on this information. To start with,

@!{ParentRule}
?Person [parent -> ?Parent] :-
  ?Parent [child -> ?Person].

This rule says that “?Parent is the parent of ?Person, if ?Person is the child of ?Parent” [1]. A rule starts with an optional, but highly recommended, rule label, followed by a rule head, the :- operator, and then the rule body. The rule label is similar to a query label, except that it does not contain variables. The rule head and body follow the normal syntax for Flora facts, and usually contain variables. The :- operator is read as “if”. The rule as a whole is an implication from the rule body to the rule head. If the rule body is true (for a given variable substitution), then the rule head is true (for the same variable substitution).

Think of rules as defining whatever property is in the rule head. You can have several rules for the same property (possibly with the exact same rule head) to describe different cases. These could even be located in different files (see Imports).

Once a rule has been defined, it is often “used by” other rules. For example, the sibling rule

@!{SiblingRule}
?Person [sibling -> ?Sibling] :-
  ?Person [parent -> ?Parent],
  ?Sibling [parent -> ?Parent],
  ?Person \== ?Sibling.

depends on the parent rule above (the \== operator means “not the same as”).

[1]This example illustrates the difficulty of paraphrasing a rule in English without using explicit variables