Manual is not ready yet, so follows quick explanation ([] means optional):

[variable :] <ReturnClass> ( [constraints] ) from collect( <SourceClass> ( [constraints] ) );

  Example:

$cheeseList  : ArrayList(size > 2) from collect( Cheese( type == $likes ) );

So, the above will collect all Cheese (source class) objects from working memory, whose type is equal to the $likes bound variable, will add them to a ArrayList (return class) and if the size of the array list is greater than 2, it will propagate the tuple, binding $cheeseList variable to that returned array list. You can use any class as a return, as long as it implements Collection interface and has a default no arg constructor.

   Accumulate is similar, though more flexible but also more verbose:

[variable :] <ReturnClass> ( [constraints] ) from accumulate( [innerVariable :] <SourceClass>( [constraints] ), init( [initialCode] ), action( [actionCode] ), result( [resultExpression] ) );

   Example:

$cheesery : Cheesery( totalAmount > 100 ) from accumulate( $cheese : Cheese( type == $likes ),
                                               init( Cheesery cheesery = new 
Cheesery(); ),
                                                action( cheesery.addCheese( 
$cheese ); ),
                                               result( cheesery ) );

Accumulate will work similar to collect, but can return an object of absolutelly any class, as long as it matches the return value of the <resultExpression>. Accumulate will execute the <initCode> once for each tuple, and right after that will execute the <actionCode> once for each matching object from <SourceClass>. After that it will return the <resultExpression> and verify if the result value matches the constraint in the <ReturnClass> (if any).
   It is easier to understand translating it to an imperative algorithm:

<initCode>
foreach matchingObject
   <declare bound inner variables>
   <actionCode>
end foreach
return <resultExpression>

Hope it helps. If anyone fancy helping to write the manual for them, :) we appreciate.

   []s
   Edson


Marcos Tengelmann wrote:

Edson,

Is the syntax explained somewhere?
-----Original Message-----
From: Edson Tirelli [mailto:[EMAIL PROTECTED] Sent: quarta-feira, 22 de novembro de 2006 09:50
To: [email protected]
Subject: Re: [drools-user] Conditions in multiple objects


  Adbeme,

  Unfortunately 3.0.x versions don't have collect. The new version
(3.1m1) has (currently in trunk). More details here:

http://markproctor.blogspot.com/2006/11/jboss-rules-3.html

  Examples of the new features:

http://anonsvn.labs.jboss.com/labs/jbossrules/trunk/drools-compiler/src/test
/resources/org/drools/integrationtests/test_Collect.drl
http://anonsvn.labs.jboss.com/labs/jbossrules/trunk/drools-compiler/src/test
/resources/org/drools/integrationtests/test_Accumulate.drl
http://anonsvn.labs.jboss.com/labs/jbossrules/trunk/drools-compiler/src/test
/resources/org/drools/integrationtests/test_AccumulateModify.drl
http://anonsvn.labs.jboss.com/labs/jbossrules/trunk/drools-compiler/src/test
/resources/org/drools/integrationtests/test_From.drl
http://anonsvn.labs.jboss.com/labs/jbossrules/trunk/drools-compiler/src/test
/resources/org/drools/integrationtests/test_From2.drl
http://anonsvn.labs.jboss.com/labs/jbossrules/trunk/drools-compiler/src/test
/resources/org/drools/integrationtests/test_FromWithParams.drl

   []s
   Edson



adbeme adbeme wrote:

Hello,

It seems that is not possible to make rules with operators like "collect" that affects the rule to a set of objects.

It is possible to simulate that behaviour of collect in some form?

I need to fire rules that have conditions over a set of objects (of same type) but i don't know how to group conditions over multiple same objects.


For example :

rule CarsStopped

when
$c:Car (stop = true) // here i need a collect, i want multiple objects in one rule that then
  print("The list of cars stoped is:$c);

end


It seems that "collect" doesnt exist. It is possible to simulate that ?

Actually i ame using JRules and want to use drools too, but i am having dificulties to do what i can do with JRules.

Thank you very much for your responses.






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

 IT executives: Red Hat still #1 for value
http://www.redhat.com/promo/vendor/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email



---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email




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

 IT executives: Red Hat still #1 for value
http://www.redhat.com/promo/vendor/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email

Reply via email to