Johan Nielsen wrote:
I want to use facts in JESS for a class structure. If I have a relationship between two classes I want that to be valid for all the sub-classes as well. So that I can check if two instances of some classes should have an instance relationship between them. Hmmm, not so clear maybe... The code below is an example that may make it more clear:Hi everyone, I think writing the question to the JESS Mail-list cleared my mind and I found a quite simple solution by adding a defquery and a deffunction, and changing the defrule as below. If anyone has another way to solve I am pleased to hear about it. Johan ; new code (defquery find-a-class  "Finds a generic feature."  (declare (variables ?gf))  (a_class (id ?gf))) (deffunction get-superclass-tree  "Returns a list of the members of ?gf:s superclass tree - (grand-) parents."  (?gf)  (bind ?it (run-query find-a-class ?gf))  (while (?it hasNext)  (bind ?token (call ?it next))  (bind ?fact (call ?token fact 1))  (bind ?parent (fact-slot-value ?fact parent))  (if (or (eq ?gf ?parent) (eq ?parent nil)) then  (return (create$ ?gf)) ; ?gf is the top parent.  else  (return (create$ ?gf (get-superclass-tree ?parent))))))      ; continue the search. ; changed code ; assert a relationship between two instances if their classes or super-classes have (defrule match-two-instances-and-any-class-relationship  (an_instance (id ?iid1) (instance_of ?io1))  (an_instance (id ?iid2&~?iid1) (instance_of ?io2))  (not (an_instance_relationship (relating ?iid1) (related ?iid2)))  (a_class_relationship (relating ?ing) (related ?ed))  (test (and (member$ ?ing (get-superclass-tree ?io1))  Â (member$ ?ed (get-superclass-tree ?io2))))  =>  (assert (an_instance_relationship (relating ?iid1) (related ?iid2)))) (clear) -- The University of Tokyo Dept. Precision Machinery Engineering Hongo 7-3-1, Bunkyo-ku Tokyo 113-8656 JAPAN |
- JESS: Matching of instances and classes Johan Nielsen
- Re: JESS: Matching of instances and classes Johan Nielsen
