Re: JESS: [EXTERNAL] Dynamic rule matching in the LHS

"Wolfgang Laun" <[email protected]> Wed, 31 Jul 2013 07:17:24 +0200
Newsgroups gmane.comp.java.jess
Message-ID <CANaj1Ld=WukTzLu18v-miS-9NQ2vBGFHZt0cDciG_6p0TYwb=w@mail.gmail.com>
On 30/07/2013, Aurelien Mazurie <[email protected]> wrote:
> Thank you very much for this answer. It seems like 'forall' will fire t=
he
> rule only if all the 'bag-of-items' facts are validated (i.e., if all o=
f
> them have 'item' facts with the names listed in their 'names' slot). Is=
 that
> correct?

Yes.

>
> If yes, then what I am trying to do is slightly different. I do expect =
to
> have some of the 'bag-of-items' facts failing the validation. What I wa=
nt is
> to act upon those who pass (and also, incidentally, on those who do not
> pass).

Ernest's rule fires on the "pass" set.

>
> Is there a way to keep track of which, among all the 'bag-of-items' fac=
ts,
> are validated by the 'forall' CE?

The negation of the "forall" is the negated existential quantifier, thus:

(defrule check-bag-NOT-valid
  (bag-of-items (names $?   ?name   $?))
  (not (item (name ?name)))
=3D>
  (printout t "The bag contains invalid " ?name crlf))

The rule fires for each of the bad items in a bag. Sometimes this is
desired. If not, the bad bag might be retracted or marked as "bad" in
an additional slot.

-W

>
> Best,
> Aur=E9lien
>
> ps: 'dynamic' may be a poor choice of words. I meant that the LHS had t=
o
> dynamically adapt to the content of a fact's multislot, different from =
one
> fact to another
>
> On Jul 30, 2013, at 8:21 AM, "Friedman-Hill, Ernest [via Jess]"
> <[email protected]> wrote:
>
>> Not sure what "dynamic" means in this context. But you can use the
>> "forall" conditional element to implement this rule. You could read th=
e
>> LHS here as "For all values of ?name in bag-of-items, there's a
>> corresponding item fact."
>>
>> (defrule check-bag-valid
>>     (forall
>>         (bag-of-items (names $?    ?name   $?))
>>         (item (name ?name)))
>>     =3D>
>>     (printout t "The bag is valid" crlf))
>>
>> NOTE: Like many complex Jess rules, this one won't fire unless before
>> adding your facts you've executed the "(reset)" command to asset
>> (initial-fact).
>
>
>
>
>
> --
> View this message in context:
> http://jess.2305737.n4.nabble.com/Dynamic-rule-matching-in-the-LHS-tp46=
54176p4654180.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]=
.
--------------------------------------------------------------------