You can slightly augment my "forall" version to fire once for each good set, 
given that bag-of-items has some kind of identifier; I'll assume a slot named 
"id". It doesn't matter what the contents are:

(defrule check-bag-valid
    (bag-of-items (id ?id) ))
    (forall
        (bag-of-items (id ?id) (names $?    ?name   $?))
        (item (name ?name)))
    =>
    (printout t "The bag is valid" crlf))

This rule could be read as "For some bag with some id, every value in the names 
slot has a matching item fact." It will fire once for every bag for which this 
condition holds.

-----Original Message-----
From: owner-jess-us...@sandia.gov [mailto:owner-jess-us...@sandia.gov] On 
Behalf Of Aurelien Mazurie
Sent: Wednesday, July 31, 2013 1:13 AM
To: jess-users
Subject: Re: JESS: [EXTERNAL] Dynamic rule matching in the LHS

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 whose 
item names, as listed in a multislot, are all represented by 'item' facts. The 
rule should not fire if one or more of these items are absent from 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 hypothetical 
rule, while the third would not, because there is no 'item' fact with name C.

The 'forall' approach suggested by M. Friedman-Hill is quite close to this, 
however it seems that the rule will fire only if _all_ the 'bag-of-items' facts 
have all of their items represented by facts. I.e., in my example above it 
would not fire until I remove the third bag-of-items fact. Once again, it is 
close but no cigar.

Best,
Aurélien

On Jul 30, 2013, at 10:54 AM, "Jason Morris" <jason.c.mor...@gmail.com> wrote:

> 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))) =>  ; 
> ...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



--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users y...@address.com'
in the BODY of a message to majord...@sandia.gov, NOT to the list (use your own 
address!) List problems? Notify owner-jess-us...@sandia.gov.
--------------------------------------------------------------------


--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users y...@address.com'
in the BODY of a message to majord...@sandia.gov, NOT to the list
(use your own address!) List problems? Notify owner-jess-us...@sandia.gov.
--------------------------------------------------------------------

Reply via email to