Re: JESS: [EXTERNAL] Dynamic rule matching in the LHS
"Jason Morris" <[email protected]> Tue, 30 Jul 2013 12:54:00 -0400
| Newsgroups | gmane.comp.java.jess |
|---|---|
| Message-ID | <CALQZ0BG_DR5BB5FkyP5ZyshbXcpBKRudvWqaTWOY=t8rjYKhhg@mail.gmail.com> |
--e89a8f6427306a896004e2bd7632 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Another "old skool" way of doing it using predicate constraints is... (clear) (deftemplate item (slot name)) (deftemplate bag-of-items (multislot item-names)) (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)) ;; Program (reset) (assert (item (name A))) (assert (item (name B))) (assert (item (name C))) (assert (bag-of-items (item-names A B C))) (run) *Jason C. Morris* President, Principal Consultant Morris Technical Solutions LLC President, Rules Fest Association Chairman, IntelliFest 2013: International Conference on Reasoning Technologies -------------------------------------------- phone: +01.517.376.8314 skype: jcmorris-mts email: [email protected] mybio: http://www.linkedin.com/in/jcmorris www.intellifest.org Invent * Innovate * Implement at IntelliFest! On Fri, Jul 26, 2013 at 4:55 PM, Aurelien Mazurie <[email protected]>wro= te: > Dear Jess users, > I am wondering how to write a rule that would dynamically match multiple > facts based on their names. > > Let say I have two types of facts; one representing the information that = an > item (with a given name) exists, and the other one representing a list of > items (e.g., as a list of names in a multislot). It could be something li= ke > this: > > (deftemplate item (slot name)) > (deftemplate bag-of-items (multislot names)) > > (assert (item (name A)) > (assert (bag-of-items (names A B)) > > What I am trying to write is a rule that would, for any bag-of-items fact= , > fire if all the items listed in the multislot 'name' are item facts that > have been asserted. > > I am wondering if there is an easy way to do that, or if I'll need to hac= k > my way through it with loops and tests in the LHS of my rule. > > Any suggestion? > Best, > Aur=C3=A9lien > > > > -- > View this message in context: > http://jess.2305737.n4.nabble.com/Dynamic-rule-matching-in-the-LHS-tp4654= 176.html > Sent from the Jess mailing list archive at Nabble.com. > > > -------------------------------------------------------------------- > 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]= --e89a8f6427306a896004e2bd7632--