<br> Basha,<br><br> This is the correct behavior since both facts match both patterns (one at a time). If you don't want them to fire 2 times, you need a way to tell the engine there is an order on the facts. I.e
., (A,B) is a valid tuple for you, but (B,A) is not. <br> One way of doing that is if the facts have some ID attribute that can be ordered:<br><br> $f1 : Message( $id1 : id, $m1 : message )<br> $f2 : Message( id > $id1, $m2 : message == $m1, eval( $f1 != $f2 ) )
<br><br> If your facts have no attribute that allow a user to establish an order between them, then the only way is to use java system id to do that:<br><br> $f1 : Message( $m1 : message )<br>
$f2 : Message( $m2 : message == $m1, eval( System.identityHashCode( $f1 ) > System.identityHashCode( $f2 ) ) )<br>
<br> []s<br> Edson<br><br><div><span class="gmail_quote">2007/11/15, Sikkandar Nawabjan <<a href="mailto:Sikkandar.Nawabjan@ust-global.com">Sikkandar.Nawabjan@ust-global.com</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Edson,<br><br>With this code it is firing. But it is firing 2 times(u also got same 2 time output). why is that? how we can avoid?<br><br>Thanks and Regss,<br><br>Basha<br><br><br><br><br><br><br><br> Sorry, my mistake. "this" is a reserved word in java (duh!!), and so you need to use your own binding:
<br><br>m : Message( $message1 : message )<br>mdup : Message($message2:message==$message1,eval(mdup != m) )<br><br> You can't use mvel dialect, because in MVEL the operators "==" and "!=" will call the equals() method anyway.
<br> Other than that, it is working just fine for me:<br><br>rule "Find duplicates"<br> salience 10<br> when<br> $f1 : Message( $m1 : message )<br> $f2 : Message( $m2 : message == $m1, eval( $f1 != $f2 ) )
<br> then<br> System.out.println( "FIRED DUPLICATE:" );<br> System.out.println( " $f1 = "+$f1+" [ message="+$m1+" ]" );<br> System.out.println( " $f2 = "+$f2+" [ message="+$m2+" ]" );
<br>end<br><br>rule "Find differents"<br> when<br> $f1 : Message( $m1 : message )<br> $f2 : Message( $m2 : message != $m1 )<br> then<br> System.out.println( "FIRED DIFFERENT:" );
<br> System.out.println( " $f1 = "+$f1+" [ message="+$m1+" ]" );<br> System.out.println( " $f2 = "+$f2+" [ message="+$m2+" ]" );<br>end<br>
<br> The code to insert facts is:<br><br> Message message1 = new Message();<br> message1.setMessage( "Hello World" );<br> workingMemory.insert( message1 );<br> Message message2 = new Message();
<br> message2.setMessage( "Hello World" );<br> workingMemory.insert( message2 );<br> Message message3 = new Message();<br> message3.setMessage( "Hello Bob" );
<br> workingMemory.insert( message3 );<br> workingMemory.fireAllRules();<br><br> And the result is:<br><br>FIRED DUPLICATE:<br> $f1 = com.sample.DroolsTest$Message@1b06041 [ message=Hello World ]
<br> $f2 = com.sample.DroolsTest$Message@1a001ff [ message=Hello World ]<br>FIRED DUPLICATE:<br> $f1 = com.sample.DroolsTest$Message@1a001ff [ message=Hello World ]<br> $f2 = com.sample.DroolsTest$Message@1b06041
[ message=Hello World ]<br>FIRED DIFFERENT:<br> $f1 = com.sample.DroolsTest$Message@1c6572b [ message=Hello Bob ]<br> $f2 = com.sample.DroolsTest$Message@1b06041 [ message=Hello World ]<br>FIRED DIFFERENT:<br> $f1 =
com.sample.DroolsTest$Message@1b06041 [ message=Hello World ]<br> $f2 = com.sample.DroolsTest$Message@1c6572b [ message=Hello Bob ]<br>FIRED DIFFERENT:<br> $f1 = com.sample.DroolsTest$Message@1c6572b [ message=Hello Bob ]
<br> $f2 = com.sample.DroolsTest$Message@1a001ff [ message=Hello World ]<br>FIRED DIFFERENT:<br> $f1 = com.sample.DroolsTest$Message@1a001ff [ message=Hello World ]<br> $f2 = com.sample.DroolsTest$Message@1c6572b
[ message=Hello Bob ]<br><br> []s<br> Edson<br><br><br><br>2007/11/14, Sikkandar Nawabjan <<a href="mailto:Sikkandar.Nawabjan@ust-global.com">Sikkandar.Nawabjan@ust-global.com</a>>:<br><br> i just use this sort of rule
<br><br> rule "Hello World"<br><br> dialect "mvel"<br><br> when<br><br> m : Message( $message1 : message )<br><br> mdup : Message($message2:message==$message1,eval(this!=m) )
<br><br> then<br><br> System.out.println("Rule Fired1111"+m +"::"+mdup );<br><br> System.out.println ("Rule Fired"+$message1 +"::"+$message2 );<br><br> end
<br><br><br><br> if i put rule parameter dialect "MVEL" the error "this should be used in static context" is gone. But now the rule is firing whatever may be the data<br><br> i assert 2 objects with message Hello and Hello11111.
<br><br> still the rule is firing(2 times).<br><br> Thanks and regs,<br><br> basha<br><br><br><br><br> Message: 1<br> Date: Wed, 14 Nov 2007 09:48:02 -0200<br> From: "Edson Tirelli" <
<a href="mailto:tirelli@post.com">tirelli@post.com</a>><br> Subject: Re: [rules-users] RE: how to find duplicate inlineeval<br> To: "Rules Users List" <<a href="mailto:rules-users@lists.jboss.org">
rules-users@lists.jboss.org</a> ><br> Message-ID:<br> <<a href="mailto:e6dd5ba30711140348p6da77e64kdac90cd313b5aa80@mail.gmail.com">e6dd5ba30711140348p6da77e64kdac90cd313b5aa80@mail.gmail.com</a>
><br> Content-Type: text/plain; charset="iso-8859-1"<br><br> Sorry, you lost me. What is the error message?<br> Can you send us a self contained test showing the problem you are having?
<br><br> []s<br> Edson<br><br> 2007/11/14, Sikkandar Nawabjan < <a href="mailto:Sikkandar.Nawabjan@ust-global.com">Sikkandar.Nawabjan@ust-global.com</a> <mailto:<a href="mailto:Sikkandar.Nawabjan@ust-global.com">
Sikkandar.Nawabjan@ust-global.com</a>> >:<br> ><br> > Edson,<br> ><br> > As you said i used inline eval. But am getting erroe message like this<br> > can't be used in static
<a href="http://context.am">context.am</a> <<a href="http://context.am/">http://context.am/</a>> using statelesssession to assert my<br> > objects.<br> ><br> > i also put eval(this!=obj1) as follows.
<br> ><br> > $obj1:Object1($id:id,$name:name)<br> > $obj2:Object1(id==$id,$name:name==$name, eval( this!=$obj1<br> > )) eval($obj2!= $obj1)<br> ><br> > Though my references are different the rule is not firing
<br> ><br> ><br> > Thanks and Regs<br> ><br> > Basha<br> ><br> > From: <a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org
</a> on behalf of Edson Tirelli<br> > Sent: Tue 11/13/2007 9:35 PM<br> > To: Rules Users List<br> > Subject: Re: [rules-users] RE: how to find duplicate<br> ><br> ><br> >
<br> ><br> > Sikkandar,<br> ><br> > The only way to check for identity is to use an inline eval and use<br> > java code to check that:<br> ><br> > when
<br> > $obj1:Object1($id:id,$name:name)<br> > $obj2:Object1(id==$id,$name:name==$name, eval( this!=$obj1 ))<br> > then<br> ><br> > Another option is to configure your rulebase to not allow the same
<br> > object to be matched by more than one pattern in your rules. To do that you<br> > can either set a system property:<br> ><br> > drools.removeIdentities = true<br> >
<br> > Or you can use drools API:<br> ><br> > RuleBaseConfiguration conf = new RuleBaseConfiguration();<br> > conf.setRemoveIdentities( true );<br> > RuleBase rulebase =
RuleBaseFactory.newRuleBase( conf );<br> ><br> > If you do that, your rule can be written as this:<br> ><br> > when<br> > $obj1:Object1($id:id,$name:name)<br> > $obj2:Object1(id==$id,$name:name==$name)
<br> > then<br> ><br> > Since the engine will never allow the same fact to simultaneously match<br> > both patterns.<br> ><br> > []s<br> > Edson
<br><br><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">
https://lists.jboss.org/mailman/listinfo/rules-users</a><br><br><br><br><br><br><br><br>--<br> Edson Tirelli<br> Software Engineer - JBoss Rules Core Developer<br> Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646
<br> JBoss, a division of Red<br><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">
https://lists.jboss.org/mailman/listinfo/rules-users</a><br><br><br></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> Software Engineer - JBoss Rules Core Developer<br> Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646
<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>