Re: JESS: [EXTERNAL] Dynamic rule matching in the LHS
"Aurelien Mazurie" <[email protected]> Tue, 30 Jul 2013 23:12:43 -0600
| Newsgroups | gmane.comp.java.jess |
|---|---|
| Message-ID | <[email protected]> |
Thank you for this tip. It is not what I am trying to achieve, however. I= must apologize if my original email was misunderstood. My goal is to write a rule that would fire for any 'bag-of-items' fact wh= ose item names, as listed in a multislot, are all represented by 'item' f= acts. The rule should not fire if one or more of these items are absent f= rom the fact list: (item (name A)) (item (name B)) (bag-of-items (item-names A)) (bag-of-items (item-names A B)) (bag-of-items (item-names A B C)) In this example the two first 'bag-of-items' facts would fire my hypothet= ical rule, while the third would not, because there is no 'item' fact wit= h name C. The 'forall' approach suggested by M. Friedman-Hill is quite close to thi= s, however it seems that the rule will fire only if _all_ the 'bag-of-ite= ms' facts have all of their items represented by facts. I.e., in my examp= le above it would not fire until I remove the third bag-of-items fact. On= ce again, it is close but no cigar. Best, Aur=E9lien On Jul 30, 2013, at 10:54 AM, "Jason Morris" <[email protected]> w= rote: > Another "old skool" way of doing it using predicate constraints is... >=20 > (clear) > (deftemplate item (slot name)) > (deftemplate bag-of-items (multislot item-names)) >=20 > (defrule fire-for-all-members-in-bag > ; If you have a bag of item names ... > (bag-of-items (item-names $?item-names)) > ; and there is an item whose name is member of this bag ... > ?item <-(item (name ?name&:(member$ ?name $?item-names))) > =3D> > ; ...then do something interesting > (printout t ?name " is in the bag!" crlf)) >=20 > ;; Program > (reset) > (assert (item (name A))) > (assert (item (name B))) > (assert (item (name C))) > (assert (bag-of-items (item-names A B C))) > (run) >=20 > *Jason C. Morris* > President, Principal Consultant > Morris Technical Solutions LLC > President, Rules Fest Association > Chairman, IntelliFest 2013: International Conference on Reasoning > Technologies -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users [email protected]' in the BODY of a message to [email protected], NOT to the list (use your own address!) List problems? Notify [email protected]= . --------------------------------------------------------------------