Hi Mike,<br><br>Thanks very much, after a few minutes of staring I think I have understood your very well put answer!<br><br>If I understand you right, what is happening is:<br><br><span><font color="#0000ff" face="Courier New" size="2">Test( $y : y
)<br><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">This means, WHEN there is an instance of Test, assign the value of its "y" property to $y</span><br style="color: rgb(0, 0, 0);"><br style="color: rgb(0, 0, 0);">
<span style="color: rgb(0, 0, 0);">AND</span><br style="color: rgb(0, 0, 0);"><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">WHEN there is an instance of Test where it's "x" property is equal to $y + 1</span><br style="color: rgb(0, 0, 0);">
<br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">THEN fire.</span><br></font></span><br><br>I think I understand that. I am going to need to do this with some pretty complicated formulae, containing up to 8 different variables. I have a fixed data set and need to find certain patterns in them based on the formulae. I have most of the program figured out, my only trouble is expressing my formulae in the correct syntax. I will try to extend this principle you have explained to me and hope it can cope with the extra complication... unless there would be a better way to achieve this?<br>
<br>I am really sorry but I am totally new to drools - but am committed to using it on a project so I guess I'm going to get to know it pretty well :-)<br><br>I read briefly that one can define a DSL, I might look at this eventually to build an easier mechanism for expressing my formulae - if that can be achieved using a DSL.<br>
<br>Can the whole rule be defined in Groovy/Java - if so I might be easier doing that. I have so much work to do!<br><br><br>many thanks<br><br>Richard<br><br><br><br><div class="gmail_quote">2008/5/2 Anstis, Michael (M.) <<a href="mailto:manstis1@ford.com">manstis1@ford.com</a>>:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2">Hi Richard,</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2">The "when" section matches fact (object) patterns, so your
requirement could be written as:-</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Courier New" size="2">when there is a Test Fact 'A' and another Test Fact 'B'
where "the 'x' property of 'A'" equals "the 'y' property of fact 'B'
plus 1" then.....</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Courier New" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2">This would become:-</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Courier New" size="2">rule "Rule 1"</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Courier New" size="2">when</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Courier New" size="2"> Test( $y : y
)</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Courier New" size="2"> Test( x == ($y + 1)
)</font></span></div><div class="Ih2E3d">
<div dir="ltr" align="left"><span><font color="#0000ff" face="Courier New" size="2">then</font></span></div>
<div dir="ltr" align="left"><span><font face="Courier New"> <font color="#0000ff" size="2">System.out.println("Rule 1 matches");</font></font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Courier New" size="2">end</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2"> </font></span></div>
</div><div><span></span><font face="Arial"><font color="#0000ff"><font size="2">By default both patterns can match the same object, so test data:-</font></font></font></div>
<div><font face="Arial"><font color="#0000ff"><font size="2"></font></font></font> </div>
<div><font><font><font color="#0000ff" face="Courier New" size="2"><span>A : x = 1, y = 1</span></font></font></font></div>
<div><font><font><font color="#0000ff" face="Courier New" size="2"><span>B : x = 2, y = 1</span></font></font></font></div>
<div><font><font><font color="#0000ff" face="Arial" size="2"><span></span></font></font></font> </div>
<div><font><font><font color="#0000ff" face="Arial" size="2"><span>Will cause the rule to activate
twice:-</span></font></font></font></div>
<div><font><font><font color="#0000ff" face="Arial" size="2"><span></span></font></font></font> </div>
<div><font><font><font color="#0000ff" face="Courier New" size="2"><span>A and B</span></font></font></font></div>
<div><font><font><font color="#0000ff" face="Courier New" size="2"><span>B and B</span></font></font></font></div>
<div><font><font><font color="#0000ff" face="Arial" size="2"><span></span></font></font></font> </div>
<div><font><font><font color="#0000ff" face="Arial" size="2"><span>With kind regards,</span></font></font></font></div>
<div><font><font><font color="#0000ff" face="Arial" size="2"><span></span></font></font></font> </div>
<div><font><font><font color="#0000ff" face="Arial" size="2"><span>Mike</span></font></font></font></div>
<div><font color="#0000ff" face="Arial" size="2"></font><br></div>
<blockquote style="margin-right: 0px;">
<div dir="ltr" align="left" lang="en-us">
<hr>
<font face="Tahoma" size="2"><b>From:</b> <a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>
[mailto:<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>] <b>On Behalf Of </b>Richard
Bremner<br><b>Sent:</b> 02 May 2008 08:53<br><b>To:</b>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br><b>Subject:</b> [rules-users] newbie question
on "when" condition syntax<br></font><br></div><div><div></div><div class="Wj3C7c">
<div></div>Hi, <br><br>say I have a class with two fields, x and y:
<br><br>public class Test { <br> int x = 1; <br> int
y = 2; <br><br> getters/setters... <br>} <br><br><br>I would like
a rule which fires when y = x + 1 <br><br>my initial thought would be
something like: <br><br>rule "Rule 1" <br>
<br> when <br>
test : Test (y == x + 1) <br>
then <br>
System.out.println("Rule 1 matches."); <br>
<br>end <br><br><br>but this is invalid syntax and I can
not find any examples of such a rule. I'm doing my best but reading the manual
etc. I'm struggling with the syntax here and can't figure it out.<br><br>any
help really appreciated! </div></div></blockquote></div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>