RE: JESS: [EXTERNAL] Matching facts based on a slot, but not the fact's type

"Friedman-Hill, Ernest" <[email protected]> Tue, 30 Jul 2013 14:11:46 +0000
Newsgroups gmane.comp.java.jess
Message-ID <[email protected]>
--_000_7F2CAF6713AFDD4392FC4DAA05671E072C827D45EXMB10srnsandia_
Content-Type: text/plain;
 charset=us-ascii
Content-Transfer-Encoding: quoted-printable

The short answer is "no". Templates are like Java classes, and so this is a=
kin to asking if you can write Java code that reads the value of a "score" =
member variable in any class.

But you can use template inheritance to achieve your goal. Templates can ex=
tend other templates; just put your "score" slot in a base template, and ex=
tend everything else that needs a "score" slot from that common base, and w=
rite your patterns to match the base template. Read about the use of "exten=
ds" in templates here:

http://www.jessrules.com/jess/docs/71/memory.html


From: [email protected] [mailto:[email protected]] On B=
ehalf Of Aurelien Mazurie
Sent: Friday, July 26, 2013 4:43 PM
To: jess-users
Subject: JESS: [EXTERNAL] Matching facts based on a slot, but not the fact'=
s type

Dear Jess users,
I am still learning the ropes, and cannot find an answer to the following q=
uestion either online or in the 'Jess in action' book. Is there a way to ma=
tch facts in a LHS based on the presence of a slot?

For example, I have two templates:

(deftemplate A (slot score))
(deftemplate B (slot score))

I would like my rule to be triggered if any fact (either from template A, B=
, or others) have a 'score' slot with a specific value. For now I can do it=
 by manually adding references to A and B in the LHS, but this will not sca=
le well. I'm looking for a solution that can just work on any fact, regardl=
ess of the template they are defined from.

Best,
Aurelien

--_000_7F2CAF6713AFDD4392FC4DAA05671E072C827D45EXMB10srnsandia_
Content-Type: text/html;
 charset=us-ascii
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
//www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"=
>
<meta name=3D"Generator" content=3D"Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
	{font-family:Verdana;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal-reply;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-family:"Calibri","sans-serif";}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=3D"EN-US" link=3D"blue" vlink=3D"purple">
<div class=3D"WordSection1">
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1F497D">The short answer is &#822=
0;no&#8221;. Templates are like Java classes, and so this is akin to asking=
 if you can write Java code that reads the value of a &#8220;score&#8221; m=
ember
 variable in any class.<o:p></o:p></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"><o:p>&nbsp;</o:p></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">But you can use template =
inheritance to achieve your goal. Templates can extend other templates; jus=
t put your &#8220;score&#8221; slot in a base template, and extend everythi=
ng
 else that needs a &#8220;score&#8221; slot from that common base, and writ=
e your patterns to match the base template. Read about the use of &#8220;ex=
tends&#8221; in templates here:<o:p></o:p></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"><o:p>&nbsp;</o:p></span><=
/p>
<p class=3D"MsoNormal"><a href=3D"http://www.jessrules.com/jess/docs/71/mem=
ory.html">http://www.jessrules.com/jess/docs/71/memory.html</a><o:p></o:p><=
/p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></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"><o:p>&nbsp;</o:p></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;"> owner-je=
[email protected] [mailto:[email protected]]
<b>On Behalf Of </b>Aurelien Mazurie<br>
<b>Sent:</b> Friday, July 26, 2013 4:43 PM<br>
<b>To:</b> jess-users<br>
<b>Subject:</b> JESS: [EXTERNAL] Matching facts based on a slot, but not th=
e fact's type<o:p></o:p></span></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class=3D"MsoNormal"><span style=3D"font-size:10.0pt;font-family:&quot;Ve=
rdana&quot;,&quot;sans-serif&quot;;color:black">Dear Jess users,&nbsp;<br>
I am still learning the ropes, and cannot find an answer to the following q=
uestion either online or in the 'Jess in action' book. Is there a way to ma=
tch facts in a LHS based on the presence of a slot?&nbsp;<br>
<br>
For example, I have two templates:&nbsp;<br>
<br>
(deftemplate A (slot score))&nbsp;<br>
(deftemplate B (slot score))&nbsp;<br>
<br>
I would like my rule to be triggered if any fact (either from template A, B=
, or others) have a 'score' slot with a specific value. For now I can do it=
 by manually adding references to A and B in the LHS, but this will not sca=
le well. I'm looking for a solution
 that can just work on any fact, regardless of the template they are define=
d from.&nbsp;<br>
<br>
Best,&nbsp;<br>
Aurelien&nbsp;</span><o:p></o:p></p>
</div>
</div>
</body>
</html>

--_000_7F2CAF6713AFDD4392FC4DAA05671E072C827D45EXMB10srnsandia_--