Hi,

I am a newbie to JESS and expert systems and have started some experimentation to get a better understanding of them. Now I encountered a problem I cannot solve in a simple way.

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:

(clear)

(deftemplate a_class (slot id) (slot parent))
(deftemplate a_class_relationship (slot relating) (slot related))
(deftemplate an_instance (slot id) (slot instance_of))
(deftemplate an_instance_relationship (slot relating) (slot related))

(deffacts some-facts
 (a_class (id class1))
 (a_class (id class1.1) (parent class1))
 (a_class (id class2))
 (a_class (id class2.1) (parent class2))
 (a_class_relationship (relating class1) (related class2.1)))

; 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)))
 ; *** PROBLEM ***
 ; match a_class_relationship that affects the instances

 =>
 (assert (an_instance_relationship (relating ?iid1) (related ?iid2))))

(watch all)
(reset)

(assert (an_instance (id i1) (instance_of class1.1)))
(assert (an_instance (id i2) (instance_of class2.1)))
(assert (an_instance (id i3) (instance_of class2)))

(run)

Now this matches for all the combinations of the instances, i.e. 6 times but I want it to match only for instance ?iid1= i1 and ?iid2=i2. Because that is what the class structure says: a_class_relationship relating class1 to the related class2.1. And since i1 is an instance of class1.1 which is a type of class1 and i2 is an instance of class2.1 I want it to match.

Is there a way by using a simle pattern that match or...?

Johan Nielsen
-- 
The University of Tokyo
Dept. Precision Machinery Engineering
Hongo 7-3-1, Bunkyo-ku
Tokyo 113-8656
JAPAN


Reply via email to