[jboss-jira] [JBoss JIRA] Commented: (JBRULES-546) Please implement "collect( ... ) from" functionality

Edson Tirelli (JIRA) jira-events at lists.jboss.org
Wed Jun 27 20:15:58 EDT 2007


    [ http://jira.jboss.com/jira/browse/JBRULES-546?page=comments#action_12367113 ] 
            
Edson Tirelli commented on JBRULES-546:
---------------------------------------

>From chaining (or maybe should be best to call it "nesting") is done. Fernando is fixing the XML parser/dumper and we should be done. 

In DRL it is like:

rule "Accumulate with From Chaining" salience 80
    when
        $cheesery : Cheesery()
        $person   : Person( $likes : likes )
    	$list     : List( size > 2 ) 
    	                       from accumulate( $cheese : Cheese( type == $likes  ) from $cheesery.getCheeses(),
                                                init( List l = new ArrayList(); ),
                                                action( l.add( $cheese ); )
                                                result( l ) )
    then
        results.add( $list );
end 

rule "test collect with nested from"
	when
		$cheesery : Cheesery()
	    $person : Person( $likes : likes )
		$list : ArrayList() from collect( Cheese( type == $likes ) from $cheesery.getCheeses() )
	then
		results.add( $list );
end

You can nest any levels of from/collect/accumulate inside an accumulate/collect element, but I don't see any real use for more than 1 level of nesting.


> Please implement "collect( ... ) from" functionality
> ----------------------------------------------------
>
>                 Key: JBRULES-546
>                 URL: http://jira.jboss.com/jira/browse/JBRULES-546
>             Project: JBoss Rules
>          Issue Type: Feature Request
>      Security Level: Public(Everyone can see) 
>            Reporter: Dirk Bergstrom
>         Assigned To: Edson Tirelli
>
> I need to count the number of sub-objects that meet various criteria.  As an example, suppose I have several hundred Town objects, each of which has a list of perhaps a few hundred Person objects.  I need to write rules like:
> "Find all the towns that have more than three disabled people with incomes over $100K."
> "For each town with more than 1000 residents that has more than 50 poor children under the age of 8, add a teacher for every 25 children."
> I'm shaky on JBR syntax, but I think those would translate to something like:
> rule "disabled"
>   when
>     ArrayList(size > 50) from collect( Person( disabled == "yes", income > 100000 ) from town.getPersons() )
>   then
>     //do stuff
> end
> rule "teachers"
>   when
>     town : Town( population > 1000 )
>     count : Arraylist from collect( Person( disabled == "yes", income > 100000 ) from town.getPersons() )
>     count( size > 50 )
>   then
>     town.addTeachers(count.size() / 25)
> end
> (I'm not really working with towns and people, but it makes for easily understood examples)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list