Search code examples
protegejess

JessTab: Finding the youngest person in family ontology


I am using the [family ontology][1] to test Jess rules. Everything works fine unless manipulating data with Jess built-in functions e.g. min and max. I have designed the following rule:

(defrule print_people_min_age 
(object  (https://wiki.csc.calpoly.edu/OntologyTutorial/family_example.owl#age ?a)) 
   => 
(printout t "Min age " (min ?a) crlf))

The rule compiles well, but I am not getting the desired output. It outputs me ages of each person in the ontology. I tried to put the min function in the LHS but it results in error.

[1]: Family Ontology https://wiki.csc.calpoly.edu/OntologyTutorial/attachment/wiki/AddingRuleWithJessTab/family_example_for_rules.owl


Solution

  • Functions (min <numeric-expresion>+) and (max <numeric-expresion>+) are meant to be applied to a number of arguments - you are calling it with just one argument. The rule fires once for each object, and the minimum of that single age is - that age.

    This rule illustrates how to find a minimum:

    (defrule print_people_min_age 
    (object  (https://wiki.csc.calpoly.edu/OntologyTutorial/family_example.owl#age ?a1))
    (not (object (https://wiki.csc.calpoly.edu/OntologyTutorial/family_example.owl#age ?a2&:(< ?a2 ?a1))))
    => 
    (printout t "Min age " ?a1 crlf))