Search code examples
ontologyrulesjess

Strange behavior in Jess


I would like to find Bob children in the family ontology using Jess. The following rule should do it:

(defrule FindBobChildren
    (object (is-a https://wiki.csc.calpoly.edu/OntologyTutorial/family_example.owl#Person) 
            (OBJECT ?oi)
            (https://wiki.csc.calpoly.edu/OntologyTutorial/family_example.owl#hasParent 
            ?b&:(eq (instance-name ?b) (instance-name https://wiki.csc.calpoly.edu/OntologyTutorial/family_example.owl#Bob)))
    )
=>
    (printout t "Bob children:" (instance-name ?oi) crlf)   
)

But, unfortunately it only prints out children who have only Bob as his/her parent. For example, if a person has Bob and Mary as his/her parents then it will not be matched by the rule.


Solution

  • Not knowing how the template of #Person is defined makes it difficult, but from the behaviour you describe I infer that #hasParent is a multislot. Therefore, use this:

    (defrule FindBobChildren
        (object (is-a #Person) 
            (OBJECT ?oi)
            (#hasParent $? ?b&:(eq (instance-name ?b)(instance-name #Bob)) $?
            )
        )
    =>
        (printout t "Bob children:" (instance-name ?oi) crlf)   
    )