<br><br><div class="gmail_quote">2010/8/27 Patricia Bogoevici <span dir="ltr">&lt;<a href="mailto:patriciabogoevici@yahoo.com">patriciabogoevici@yahoo.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
Thx for your answer, Wolfgang.<br><br>While your advice makes sense, it does not help me. I cannot avoid using OR. I use Drools for validation and I have some cases when I need to use OR between conditions for evaluating an invalid state.</td>
</tr></tbody></table></blockquote><div><br>Well, I just wrote a substantial number of rules for data validation, and I never felt the need to use &quot;or&quot;. Care to post an example where you think you can&#39;t avoid it?<br>
<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
Also, the solution you proposed works fine when the rule works with one object type only. If there are more than 1, it does not work.</td></tr></tbody></table></blockquote><div><br>Right, but or-ing two facts of entirely different types produces a rather limited CE: you cannot, for instance, bind a LHS variable to such a CE. This means that, later on and on the RHS, you don&#39;t know which of these actually matched.<br>
<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
 A workaround I see, would be to separate each of the condition from OR, into separate rule. But that adds the overhead of managing multiple rules.<br></td></tr></tbody></table></blockquote><div><br>True, and this is one (perhaps the only one) point in favour of &quot;or&quot;.<br>
 <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
<br>In Expert, 5.1 manual, there is an example of how to chain expressions in DSL, using OR. They mention mapping OR being sensible, but I wish there were more details about that sensible thing.<br>--quote from the manual:<br>
&quot;<br>Example 4.77. Chaining DSL Expressions<br><br> There is a person called Bob who is happy<br>  Or<br>There is
 a person called Mike who is sad<br>Of course this assumes that &quot;Or&quot; is mapped to the &quot;or&quot; conditional element (which is a sensible thing to do).<br>&quot;<br>--end quote<br></td></tr></tbody></table>
</blockquote><div><br>Heh :)<br>What the author is trying to say here is that only a moron would map &quot;Or&quot; to &quot;and&quot;.<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
<br>So, my question was:  <br>Is any solution to chain conditions using eval, without having the rule firing multiple times? From your answer, it seems not, and it seems that will not be possible due to some Rete-level refactoring or optimization (hope I got your message correct, I do not know how RETE works). Is that true?</td>
</tr></tbody></table></blockquote><div><br>Yes. - As for Rete, you could read <a href="http://www.jessrules.com/jess/docs/71/rete.html">this</a>. The syntax of the rules is a little different, but you should get an idea about the general principle and where optimization kicks in.<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
 <br><br>I believe, I can live with this limitation (rule fires multiple times).</td></tr></tbody></table></blockquote><div><br>You could avoid this, technically, by adding additional CEs, but if you can live with it, it may not be worth the effort.<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
 I only hope that there is no other implication, that I am not aware of right now.<br></td></tr></tbody></table></blockquote><div><br>I don&#39;t think there is.<br><br>-W<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
<br>Thanks,<br>Patricia<br><br>--- On <b>Fri, 8/27/10, Wolfgang Laun <i>&lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;">
<br>From: Wolfgang Laun &lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;<br>Subject: Re:
 [rules-users] Drools Guvnor: Rule fires multiple times when using eval and OR<br>To: &quot;Rules Users List&quot; &lt;<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>&gt;<br>Date: Friday, August 27, 2010, 3:32 AM<br>
<br><div>My advice is: Try to avoid the Conditional Element &quot;or&quot;. From the<br>&quot;Expert&quot; manual: &quot;The engine actually has no understanding of the<br>Conditional Element &#39;or&#39;,...&quot; So, if the engine doesn&#39;t &quot;understand&quot;<br>
it, how can we? ;-)<br><br>More seriously now, there is general consent that a CE &quot;or&quot; should<br>ultimately result in two (or more) disjunct (sub-)rules, firing<br>independently. But this clear strategy is apparently countered (you<br>
could even say marred) by some Rete-level refactoring or optimization.<br><br>Anyway, in your case, a &quot;healthy&quot; solution is to write<br><br>rule &quot;any blank&quot;<br>when<br>    Asset( eval( StringUtil.isBlank(name) || StringUtil.isBlank(tag)
 ))<br>then<br>   //...<br>end<br><br>-W<br><br><br>2010/8/27 Patricia Bogoevici &lt;<a href="http://mc/compose?to=patriciabogoevici@yahoo.com" target="_blank">patriciabogoevici@yahoo.com</a>&gt;<br>&gt;<br>&gt; Hi all,<br>
&gt;<br>&gt; I am using Drools Guvnor 5.1. I created a rule that uses eval, and OR for conditions. When I tested the rule, I noticed in the log, that actually the rule fired twice.<br>&gt; The error seemed to be caused by eval and or combination. When I re-wrote the rule to not use eval, it fired only once. Also, I re-wrote the rule to use eval, but AND for conditions, again, the rule fired once as expected.<br>
&gt; I wonder if there is any other rule attribute besides no-loop, and lock-on-active that I can use to not have the rule firing twice. Or if there is any way to make the rule not firing twice.The main problem for me, is that after the rule is executed, there are 2 objects
 created.<br>&gt;<br>&gt; Below is the rule test scenario, and audit log:<br>&gt;<br>&gt;<br>&gt; Rule with eval and OR, rule fires twice<br>&gt;     rule &quot;test_rule_1&quot;<br>&gt;         lock-on-active true<br>&gt;         no-loop true<br>
&gt;         dialect &quot;mvel&quot;<br>&gt;         when<br>&gt;             Asset(eval(StringUtils.isBlank(name)))<br>&gt;              or<br>&gt;             Asset(eval(StringUtils.isBlank(tag)))<br>&gt;         then<br>
&gt;             Assetfact0 = new Asset();<br>&gt;             fact0.setStatus( &quot;INVALID&quot;
 );<br>&gt;             insert(fact0 );<br>&gt;     end<br>&gt;<br>&gt; Audit log:<br>&gt; OBJECT ASSERTED value:Asset( model=MODEL, status=null, tag=null, classification=null, name=null, serial=null ) factId: 1<br>&gt; FIRING rule: [test_rule_1] activationId:test_rule_1 [1] declarations:<br>
&gt; OBJECT ASSERTED value:Asset( model=null, status=INVALID, tag=null, classification=null, name=null, serial=null ) factId: 2<br>&gt; FIRING rule: [test_rule_1] activationId:test_rule_1 [1] declarations:<br>&gt; OBJECT ASSERTED value:Asset( model=null, status=INVALID, tag=null, classification=null, name=null, serial=null ) factId: 3<br>
&gt;<br>&gt; Rule with eval and AND, rule fires only once:<br>&gt;     rule &quot;test_rule_2&quot;<br>&gt;         lock-on-active true<br>&gt;         no-loop true<br>&gt;    
     dialect &quot;mvel&quot;<br>&gt;         when<br>&gt;             Asset(eval(StringUtils.isBlank(name)))<br>&gt;             Asset(eval(StringUtils.isBlank(tag)))<br>&gt;         then<br>&gt;             Assetfact0 = new Asset();<br>
&gt;             fact0.setStatus( &quot;INVALID&quot; );<br>&gt;             insert(fact0 );<br>&gt;     end<br>&gt;<br>&gt; Audit log:<br>&gt; OBJECT ASSERTED value:Asset( model=MODEL, status=null, tag=null, classification=null, name=null, serial=null ) factId: 1<br>
&gt; FIRING rule: [test_rule_2] activationId:test_rule_2 [1] declarations:<br>&gt; OBJECT ASSERTED value:Asset( model=null, status=INVALID,
 tag=null, classification=null, name=null, serial=null ) factId: 2<br>&gt;<br>&gt; Rule with simple string validation instead of eval. The rule fires only once.<br>&gt;<br>&gt;     rule &quot;test_rule_3&quot;<br>&gt;         lock-on-active true<br>
&gt;         no-loop true<br>&gt;         dialect &quot;mvel&quot;<br>&gt;         when<br>&gt;             Asset(name==&quot;&#39;&#39;&quot;)<br>&gt;              or<br>&gt;             Asset(tag==&quot;&#39;&#39;&#39;&quot;)<br>
&gt;         then<br>&gt;             Assetfact0 = new Asset();<br>&gt;             fact0.setStatus( &quot;INVALID&quot; );<br>&gt;
             insert(fact0 );<br>&gt;     end<br>&gt;<br>&gt;<br>&gt; Audit log:<br>&gt; OBJECT ASSERTED value:Asset( model=MODEL, status=null, tag=null, classification=null, name=&#39;&#39;, serial=null ) factId: 1<br>&gt; FIRING rule: [test_rule_3] activationId: test_rule_3 [1] declarations:<br>
&gt; OBJECT ASSERTED value:Asset( model=null, status=INVALID, tag=null, classification=null, name=null, serial=null ) factId: 2<br>&gt;<br>&gt;<br>&gt; Thanks,<br>&gt; Patricia<br>&gt;<br>&gt;<br>&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>&gt; <a href="http://mc/compose?to=rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br><br>_______________________________________________<br>rules-users mailing list<br><a href="http://mc/compose?to=rules-users@lists.jboss.org" target="_blank">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>
</div></blockquote></td></tr></tbody></table><br>

      <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>