[rules-users] accumulate / collect behaviour question - anoth er stupid question

Olenin, Vladimir (MOH) Vladimir.Olenin at moh.gov.on.ca
Thu Feb 22 09:52:26 EST 2007


> So, you are right: action will be executed 10 times for each id and eval 
> will be executed 1 time for each id.

Hmm... So, the 'action' part of the _rule_ (NOT of the accumulate statement)
will be called 100 times? How should the rule be modified for the action to
be called only 10 times? (once per each unique transaction id). Basically
the idea is to do smth if all debit operations are not balanced with credit
operations within the same transaction id....

Or have I misunderstood





-----Original Message-----
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Edson Tirelli
Sent: 21 February 2007 17:19
To: Rules Users List
Subject: Re: [rules-users] accumulate / collect behaviour question - another
stupid question

  Vlad,

Inside an accumulate CE, the action code will be executed once for each 
match of the given pattern (TransactionEntry in this case).
Eval CEs are executed once for each tuple that matches all previous 
patterns.
So, you are right: action will be executed 10 times for each id and eval 
will be executed 1 time for each id.

To understand better how forward rule engines work, there are some books 
and articles listed in JBoss Rules project page. I can personally 
recomend "Expert Systems..." by Gary Riley.

And don't worry about asking. Usually people ask a lot in the begining 
and then when they feel confident, they start to answer more than ask. :)

[]s
Edson

Olenin, Vladimir (MOH) wrote:

> Hi,
>
> Edson quoted the following sample rule some time ago:
>
> rule "transaction consistency"
>
> when
>
> Transaction( $id : id )
>
> $credits: Double( )
>
> from accumulate( TransactionEntry( id == $id, operation == "credit", 
> $amount : amount ),
>
> init( double balance = 0 ),
>
> action( balance += $amount ),
>
> result( new Double( balance ) ) );
>
> $debits: Double( )
>
> from accumulate( TransactionEntry( id == $id, operation == "debit", 
> $amount : amount ),
>
> init( double balance = 0 ),
>
> action( balance -= $amount ),
>
> result( new Double( balance ) ) );
>
> eval( ! $credits.equals( $debits ) ) then
>
> // inconsistency for transaction $id
>
> End
>
> If there are 100 transactions overall and only 10 unique transaction 
> ids (eg, id = 1..10), so that we have on average 10 Transaction facts 
> per id,
>
> - how many times will 'eval' be called?
>
> - how many times will the action be called, assuming 'eval' always 
> returns 'true'?
>
> I guess the answer for the above should be '10 times', once per each 
> id? What if I put another eval statement like "eval($id == 1)" after 
> existing 'eval'? Would that be evaluated 100 times (for all 
> Transaction facts) or only 10 times (once per unique id)?
>
> I think I'm missing quite significant piece on how tuples are selected 
> in DROOLS and how 'eval' and new 'from accumulate' features work.... Any 
> pointers would be greatly appreciated! (would some general literature 
> on rule engines help to clear up this types of questions?...)
>
> Thanks,
>
> Vlad
>
> PS: sorry for posting so many questions and answering so few.....
>
>------------------------------------------------------------------------
>
>_______________________________________________
>rules-users mailing list
>rules-users at lists.jboss.org
>https://lists.jboss.org/mailman/listinfo/rules-users
>  
>


-- 
 Edson Tirelli
 Software Engineer - JBoss Rules Core Developer
 Office: +55 11 3124-6000
 Mobile: +55 11 9218-4151
 JBoss, a division of Red Hat @ www.jboss.com


_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



More information about the rules-users mailing list