Sorry, my mistake. "this" is a reserved word in java (duh!!), and so you need to use your own binding:
m : Message( $message1 : message ) mdup : Message($message2:message==$message1,eval(mdup != m) ) You can't use mvel dialect, because in MVEL the operators "==" and "!=" will call the equals() method anyway. Other than that, it is working just fine for me: rule "Find duplicates" salience 10 when $f1 : Message( $m1 : message ) $f2 : Message( $m2 : message == $m1, eval( $f1 != $f2 ) ) then System.out.println( "FIRED DUPLICATE:" ); System.out.println( " $f1 = "+$f1+" [ message="+$m1+" ]" ); System.out.println( " $f2 = "+$f2+" [ message="+$m2+" ]" ); end rule "Find differents" when $f1 : Message( $m1 : message ) $f2 : Message( $m2 : message != $m1 ) then System.out.println( "FIRED DIFFERENT:" ); System.out.println( " $f1 = "+$f1+" [ message="+$m1+" ]" ); System.out.println( " $f2 = "+$f2+" [ message="+$m2+" ]" ); end The code to insert facts is: Message message1 = new Message(); message1.setMessage( "Hello World" ); workingMemory.insert( message1 ); Message message2 = new Message(); message2.setMessage( "Hello World" ); workingMemory.insert( message2 ); Message message3 = new Message(); message3.setMessage( "Hello Bob" ); workingMemory.insert( message3 ); workingMemory.fireAllRules(); And the result is: FIRED DUPLICATE: $f1 = [EMAIL PROTECTED] [ message=Hello World ] $f2 = [EMAIL PROTECTED] [ message=Hello World ] FIRED DUPLICATE: $f1 = [EMAIL PROTECTED] [ message=Hello World ] $f2 = [EMAIL PROTECTED] [ message=Hello World ] FIRED DIFFERENT: $f1 = [EMAIL PROTECTED] [ message=Hello Bob ] $f2 = [EMAIL PROTECTED] [ message=Hello World ] FIRED DIFFERENT: $f1 = [EMAIL PROTECTED] [ message=Hello World ] $f2 = [EMAIL PROTECTED] [ message=Hello Bob ] FIRED DIFFERENT: $f1 = [EMAIL PROTECTED] [ message=Hello Bob ] $f2 = [EMAIL PROTECTED] [ message=Hello World ] FIRED DIFFERENT: $f1 = [EMAIL PROTECTED] [ message=Hello World ] $f2 = [EMAIL PROTECTED] [ message=Hello Bob ] []s Edson 2007/11/14, Sikkandar Nawabjan <[EMAIL PROTECTED]>: > > i just use this sort of rule > > rule "Hello World" > > dialect "mvel" > > when > > m : Message( $message1 : message ) > > mdup : Message($message2:message==$message1,eval(this!=m) ) > > then > > System.out.println("Rule Fired1111"+m +"::"+mdup ); > > System.out.println("Rule Fired"+$message1 +"::"+$message2 ); > > end > > > > 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 > > i assert 2 objects with message Hello and Hello11111. > > still the rule is firing(2 times). > > Thanks and regs, > > basha > > > > > Message: 1 > Date: Wed, 14 Nov 2007 09:48:02 -0200 > From: "Edson Tirelli" <[EMAIL PROTECTED]> > Subject: Re: [rules-users] RE: how to find duplicate inlineeval > To: "Rules Users List" <rules-users@lists.jboss.org> > Message-ID: > <[EMAIL PROTECTED]> > Content-Type: text/plain; charset="iso-8859-1" > > Sorry, you lost me. What is the error message? > Can you send us a self contained test showing the problem you are > having? > > []s > Edson > > 2007/11/14, Sikkandar Nawabjan <[EMAIL PROTECTED]>: > > > > Edson, > > > > As you said i used inline eval. But am getting erroe message like this > > can't be used in static context.am using statelesssession to assert my > > objects. > > > > i also put eval(this!=obj1) as follows. > > > > $obj1:Object1($id:id,$name:name) > > $obj2:Object1(id==$id,$name:name==$name, eval( this!=$obj1 > > )) eval($obj2!= $obj1) > > > > Though my references are different the rule is not firing > > > > > > Thanks and Regs > > > > Basha > > > > From: [EMAIL PROTECTED] on behalf of Edson Tirelli > > Sent: Tue 11/13/2007 9:35 PM > > To: Rules Users List > > Subject: Re: [rules-users] RE: how to find duplicate > > > > > > > > > > Sikkandar, > > > > The only way to check for identity is to use an inline eval and use > > java code to check that: > > > > when > > $obj1:Object1($id:id,$name:name) > > $obj2:Object1(id==$id,$name:name==$name, eval( this!=$obj1 )) > > then > > > > Another option is to configure your rulebase to not allow the same > > object to be matched by more than one pattern in your rules. To do that > you > > can either set a system property: > > > > drools.removeIdentities = true > > > > Or you can use drools API: > > > > RuleBaseConfiguration conf = new RuleBaseConfiguration(); > > conf.setRemoveIdentities( true ); > > RuleBase rulebase = RuleBaseFactory.newRuleBase( conf ); > > > > If you do that, your rule can be written as this: > > > > when > > $obj1:Object1($id:id,$name:name) > > $obj2:Object1(id==$id,$name:name==$name) > > then > > > > Since the engine will never allow the same fact to simultaneously > match > > both patterns. > > > > []s > > Edson > > > > _______________________________________________ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > > > -- Edson Tirelli Software Engineer - JBoss Rules Core Developer Office: +55 11 3529-6000 Mobile: +55 11 9287-5646 JBoss, a division of Red Hat @ www.jboss.com
_______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users