Re: [rules-users] RE: Duplicate check using dialect(firing multiple times)

2007-11-15 Thread Edson Tirelli
Basha,

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.
One way of doing that is if the facts have some ID attribute that can be
ordered:

$f1 : Message( $id1 : id, $m1 : message )
$f2 : Message( id  $id1, $m2 : message == $m1, eval( $f1 != $f2 ) )

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:

$f1 : Message( $m1 : message )
$f2 : Message( $m2 : message == $m1, eval( System.identityHashCode(
$f1 )  System.identityHashCode( $f2 ) ) )

[]s
Edson

2007/11/15, Sikkandar Nawabjan [EMAIL PROTECTED]:

 Edson,

 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?

 Thanks and Regss,

 Basha







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 Fired+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 Hello1.

 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]mailto:
 [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 http://context.am/ using
 statelesssession to assert my
  objects.
   

RE: [rules-users] RE: Duplicate check using dialect(firing multiple times)

2007-11-14 Thread Sikkandar Nawabjan
Edson,

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?

Thanks and Regss,

Basha

 

 

 

   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 Fired+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 Hello1.

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] mailto:[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 http://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: