Re: JESS: [EXTERNAL] Adding facts that are instances of from-class deftemplates

"Henrique Lopes Cardoso" <[email protected]> Fri, 10 May 2013 16:55:11 +0100
Newsgroups gmane.comp.java.jess
Message-ID <CALLS5+Bq-z82HQyGnyQJto+g2X9K9e3bnGK86peMrhrSBGcJGw@mail.gmail.com>
--089e015372082f4b5204dc5f31a0
Content-Type: text/plain;
 charset=windows-1252
Content-Transfer-Encoding: quoted-printable

Thanks for the dog analogy...

But going back to practical uses, one aspect that I like when creating a
fact directly from a from-class template (i.e., a doghouse without a dog --
I can still make some reasoning over the doghouse) is that the Jess code to
do it is much more readable and compact, since you provide values for named
slots.
Something like:


(deftemplate Person (declare (from-class Person)))****
(assert (Person (name "Henrique") (age 38)))

When using definstance, I would have to go:
    (bind ?p (new Person "Henrique" 38))    ; assuming there is such a
constructor
    (definstance Person ?p)

or
    (bind ?p (new Person))
    (?p setName "Henrique")
    (?p setAge 38)
    (definstance Person ?p)

Now, when you have a class with many data members this becomes quite
complex.

Any comments? Thanks!

Henrique



On Fri, May 10, 2013 at 3:21 PM, Friedman-Hill, Ernest
<[email protected]>wrote:

>  The **real** way to add shadow facts is using the =93definstance=94
> function. It has a number of options that aren=92t available with =93add=
=94. The
> =93add=94 function was added to Jess to support the simplified semantics =
of
> JSR-94 (the javax.rules API) but the intent is that most Jess users will
> use =93definstance.=94****
>
> ** **
>
> Asserting a fact directly from a from-class template is like buying a
> doghouse; you don=92t expect to go out the next morning and find that som=
ehow
> it has a dog in it, right? It=92s certainly something you can do, but in
> normal life it=92s not very useful; usually you get a doghouse when you b=
uy a
> dog, and =93add=94 and =93definstance=94 will both get you a doghouse for=
 your Java
> object =93dog=94 automatically.****
>
> ** **
>
> *From:* [email protected] [mailto:[email protected]] =
*On
> Behalf Of *Henrique Lopes Cardoso
> *Sent:* Friday, May 10, 2013 4:54 AM
> *To:* jess-users
> *Subject:* JESS: [EXTERNAL] Adding facts that are instances of from-class
> deftemplates****
>
> ** **
>
> Hi,****
>
> ** **
>
> I am concerned with the at least two different ways in which you can add,
> to working memory, facts that are instances of from-class deftemplates.**=
*
> *
>
> Lets say I have:****
>
> ** **
>
> (deftemplate FC (declare (from-class FC)))****
>
> ** **
>
> I can add a shadow fact like this:****
>
> ** **
>
> (bind ?fc (new FC))****
>
> (add ?fc)****
>
> ** **
>
> This is the general approach described in Section 5.3.2 of the Jess manua=
l.
> ****
>
> But I can also simply go like:****
>
> ** **
>
> (assert (FC))****
>
> ** **
>
> I guess in this case I do not get a shadow fact, since the OBJECT slot is
> nil.****
>
> ** **
>
> So, my question is: if my facts are not supposed to be changed from Java
> code, is there any difference in using each of these approaches?****
>
> Section 5.3 from the Jess manual does not even mention that instances of
> from-class deftemplates can be created using the second approach above.**=
*
> *
>
> ** **
>
> Thanks!****
>
> ** **
>
> Henrique****
>
> ** **
>



--=20

----- - - - - -  -  -  -  -  -   -   -

Henrique Lopes Cardoso
DEI/FEUP
Rua Dr. Roberto Frias | 4200-465 Porto
PORTUGAL
 VoIP: (+351) 220413355
Phone: (+351) 225081400 [email protected] | www.fe.up.pt/~hlc
----- - - - - -  -  -  -  -  -   -   -

--089e015372082f4b5204dc5f31a0
Content-Type: text/html;
 charset=windows-1252
Content-Transfer-Encoding: quoted-printable

<div>Thanks for the dog analogy...</div><div><br></div><div>But going back =
to practical uses, one aspect that I like when creating a fact directly fro=
m a from-class template (i.e.,=A0a doghouse without a dog -- I can still ma=
ke some reasoning over the doghouse) is that the Jess code to do it is much=
 more readable and compact, since you provide values for named slots.</div>
<div>Something like:</div><div><div><p class=3D"MsoNormal"><br></p><p class=
=3D"MsoNormal">(deftemplate Person (declare (from-class Person)))<u></u><u>=
</u></p></div><div></div></div><div>(assert (Person (name &quot;Henrique&qu=
ot;) (age 38)))</div>
<div><br></div><div>When using definstance, I would have to go:</div><div>=
=A0 =A0 (bind ?p (new Person &quot;Henrique&quot; 38)) =A0 =A0; assuming th=
ere is such a constructor</div><div><div>=A0 =A0 (definstance Person ?p)</d=
iv></div>
<div><br></div><div>or</div><div>=A0 =A0 (bind ?p (new Person))</div><div>=
=A0 =A0 (?p setName &quot;Henrique&quot;)</div><div>=A0 =A0 (?p setAge 38)<=
/div><div>=A0 =A0 (definstance Person ?p)</div><div><br></div><div>Now, whe=
n you have a class with many data members this becomes quite complex.</div>
<div><br></div><div>Any comments? Thanks!</div><div><br></div><div>Henrique=
</div><div><br></div><br><br><div class=3D"gmail_quote">On Fri, May 10, 201=
3 at 3:21 PM, Friedman-Hill, Ernest <span dir=3D"ltr">&lt;<a href=3D"mailto=
:[email protected]" target=3D"_blank">[email protected]</a>&gt;</span> wr=
ote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">





<div lang=3D"EN-US" link=3D"blue" vlink=3D"purple">
<div>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1f497d">The *<b>real</b>* way to =
add shadow facts is using the =93definstance=94 function. It has a number o=
f options that aren=92t available with =93add=94. The =93add=94 function
 was added to Jess to support the simplified semantics of JSR-94 (the javax=
.rules API) but the intent is that most Jess users will use =93definstance.=
=94<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u>=A0<u></u></span><=
/p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1f497d">Asserting a fact directly=
 from a from-class template is like buying a doghouse; you don=92t expect t=
o go out the next morning and find that somehow it has a dog
 in it, right? It=92s certainly something you can do, but in normal life it=
=92s not very useful; usually you get a doghouse when you buy a dog, and =
=93add=94 and =93definstance=94 will both get you a doghouse for your Java =
object =93dog=94 automatically.<u></u><u></u></span></p>

<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u>=A0<u></u></span><=
/p>
<p class=3D"MsoNormal"><b><span style=3D"font-size:10.0pt;font-family:&quot=
;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style=3D"font-s=
ize:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> <a href=
=3D"mailto:[email protected]" target=3D"_blank">owner-jess-users@=
sandia.gov</a> [mailto:<a href=3D"mailto:[email protected]" targe=
t=3D"_blank">[email protected]</a>]
<b>On Behalf Of </b>Henrique Lopes Cardoso<br>
<b>Sent:</b> Friday, May 10, 2013 4:54 AM<br>
<b>To:</b> jess-users<br>
<b>Subject:</b> JESS: [EXTERNAL] Adding facts that are instances of from-cl=
ass deftemplates<u></u><u></u></span></p><div><div class=3D"h5">
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<div>
<p class=3D"MsoNormal">Hi,<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">I am concerned with the at least two different ways =
in which you can add, to working memory, facts that are instances of from-c=
lass deftemplates.<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal">Lets say I have:<u></u><u></u></p>
</div>
<div>
<div>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">(deftemplate FC (declare (from-class FC)))<u></u><u>=
</u></p>
</div>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">I can add a shadow fact like this:<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">(bind ?fc (new FC))<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal">(add ?fc)<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">This is the general approach described in Section 5.=
3.2 of the Jess manual.<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal">But I can also simply go like:<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">(assert (FC))<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">I guess in this case I do not get a shadow fact, sin=
ce the OBJECT slot is nil.<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">So, my question is: if my facts are not supposed to =
be changed from Java code, is there any difference in using each of these a=
pproaches?<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal">Section 5.3 from the Jess manual does not even menti=
on that instances of from-class deftemplates can be created using the secon=
d approach above.<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">Thanks!<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">Henrique<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
</div>
</div></div></div>
</div>

</blockquote></div><br><br clear=3D"all"><div><br></div>-- <br><pre cols=3D=
"72">----- - - - - -  -  -  -  -  -   -   -</pre><pre cols=3D"72">Henrique =
Lopes Cardoso
DEI/FEUP
Rua Dr. Roberto Frias | 4200-465 Porto
PORTUGAL
 VoIP: (+351) 220413355
Phone: (+351) 225081400 ext.1315
<a href=3D"mailto:[email protected]" target=3D"_blank">[email protected]</a> | <a hre=
f=3D"http://www.fe.up.pt/~hlc" target=3D"_blank">www.fe.up.pt/~hlc</a>
----- - - - - -  -  -  -  -  -   -   -</pre>

--089e015372082f4b5204dc5f31a0--