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

"Aurelien Mazurie" <[email protected]> Tue, 30 Jul 2013 12:58:17 -0700
Newsgroups gmane.comp.java.jess
Message-ID <[email protected]>
------=_Part_215656_1560493.1375214297139
Content-Type: text/plain;
 charset=utf-8
Content-Transfer-Encoding: quoted-printable

Thank you very much for this answer. It seems like 'forall' will fire the r=
ule only if all the 'bag-of-items' facts are validated (i.e., if all of the=
m have 'item' facts with the names listed in their 'names' slot). Is that c=
orrect?

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

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

Best,
Aur=C3=A9lien

ps: 'dynamic' may be a poor choice of words. I meant that the LHS had to dy=
namically adapt to the content of a fact's multislot, different from one fa=
ct to another

On Jul 30, 2013, at 8:21 AM, "Friedman-Hill, Ernest [via Jess]" <ml-node+s2=
[email protected]> wrote:

> Not sure what "dynamic" means in this context. But you can use the "foral=
l" conditional element to implement this rule. You could read the LHS here =
as "For all values of ?name in bag-of-items, there's a corresponding item f=
act."=20
>=20
> (defrule check-bag-valid=20
>     (forall=20
>         (bag-of-items (names $?    ?name   $?))=20
>         (item (name ?name)))=20
>     =3D>=20
>     (printout t "The bag is valid" crlf))=20
>=20
> NOTE: Like many complex Jess rules, this one won't fire unless before add=
ing your facts you've executed the "(reset)" command to asset (initial-fact=
).=20





--
View this message in context: http://jess.2305737.n4.nabble.com/Dynamic-rul=
e-matching-in-the-LHS-tp4654176p4654180.html
Sent from the Jess mailing list archive at Nabble.com.
------=_Part_215656_1560493.1375214297139
Content-Type: text/html;
 charset=UTF8
Content-Transfer-Encoding: quoted-printable

Thank you very much for this answer. It seems like 'forall' will fire the r=
ule only if all the 'bag-of-items' facts are validated (i.e., if all of the=
m have 'item' facts with the names listed in their 'names' slot). Is that c=
orrect?
<br/><br/>If yes, then what I am trying to do is slightly different. I do e=
xpect to have some of the 'bag-of-items' facts failing the validation. What=
 I want is to act upon those who pass (and also, incidentally, on those who=
 do not pass).
<br/><br/>Is there a way to keep track of which, among all the 'bag-of-item=
s' facts, are validated by the 'forall' CE?
<br/><br/>Best,
<br/>Aur=C3=A9lien
<br/><br/>ps: 'dynamic' may be a poor choice of words. I meant that the LHS=
 had to dynamically adapt to the content of a fact's multislot, different f=
rom one fact to another
<br/><br/>On Jul 30, 2013, at 8:21 AM, &quot;Friedman-Hill, Ernest [via Jes=
s]&quot; &lt;<a href=3D"/user/SendEmail.jtp?type=3Dnode&node=3D4654180&i=3D=
0" target=3D"_top" rel=3D"nofollow" link=3D"external">[hidden email]</a>&gt=
; wrote:
<br/><div class=3D'shrinkable-quote'><br/>&gt; Not sure what &quot;dynamic&=
quot; means in this context. But you can use the &quot;forall&quot; conditi=
onal element to implement this rule. You could read the LHS here as &quot;F=
or all values of ?name in bag-of-items, there's a corresponding item fact.&=
quot;=20
<br/>&gt;=20
<br/>&gt; (defrule check-bag-valid=20
<br/>&gt; &nbsp; &nbsp; (forall=20
<br/>&gt; &nbsp; &nbsp; &nbsp; &nbsp; (bag-of-items (names $? &nbsp; &nbsp;=
?name &nbsp; $?))=20
<br/>&gt; &nbsp; &nbsp; &nbsp; &nbsp; (item (name ?name)))=20
<br/>&gt; &nbsp; &nbsp; =3D&gt;=20
<br/>&gt; &nbsp; &nbsp; (printout t &quot;The bag is valid&quot; crlf))=20
<br/>&gt;=20
<br/>&gt; NOTE: Like many complex Jess rules, this one won't fire unless be=
fore adding your facts you've executed the &quot;(reset)&quot; command to a=
sset (initial-fact).=20
</div><br/>

=09
=09
=09
<br/><hr align=3D"left" width=3D"300" />
View this message in context: <a href=3D"http://jess.2305737.n4.nabble.com/=
Dynamic-rule-matching-in-the-LHS-tp4654176p4654180.html">Re: JESS: [EXTERNA=
L] Dynamic rule matching in the LHS</a><br/>
Sent from the <a href=3D"http://jess.2305737.n4.nabble.com/">Jess mailing l=
ist archive</a> at Nabble.com.<br/>
------=_Part_215656_1560493.1375214297139--