RulesΒΆ

Rules in Sunflower define relationships not explicitly stated in the KB. In other words, we can use rules to deduce higher order facts from simple ones. For example, suppose we have a KB with information about a set of individuals and their offsprings, like in the case of family.flr, and if we have a rule which defines the relationship between an individual and the individual’s great grand parents, we can use the rule to query the KB for individuals who are great grand parents.

A rule in Sunflower has the following generic syntax:

@!{NameOfRule}
RULE HEAD :- RULE BODY.

where RULE HEAD is the higher order fact we are trying to establish, and RULE BODY is one or more statements which must be true in order for RULE HEAD to be true.

An example of a Sunflower rule is the ‘GreatGrandParentRule’ from family.flr. It is shown below:

@!{GreatGrandparentRule}
?Person [greatGrandparent -> ?GreatGrandparent] :-
  ?Person [grandparent -> ?GrandParent],
  ?GrandParent [parent -> ?GreatGrandparent].

This rule says that ?Person has great grand parent ?GreatGrandparent if ?Person has ?GrandParent as a grand parent, and ?GrandParent has ?GreatGrandparent as a parent.