You have to establish one representative of each subgroup that is markedly distinct from all of its siblings in the same subgroup. This triggers a single firing for a unique a/b combination. Then you can collect all those that match the representative. With attribute c being what it is in your example:

Fact( $a: a, $b: b, $c: c )
not Fact( c < $c )
$list: List() from collect ( Fact( a == $a, b == $b ) )

-W

On 14 May 2012 21:05, Mike Goldner <mike@thegoldners.com> wrote:
I have a single rule that includes a "collect" pattern to pass a collection to the RHS.  However, what I now need to do fire this rule for multiple collections based on groupings defined by attributes on the fact.

Here is an example:

Fact(a = 1, b = 1, c = 1)
Fact(a = 1, b = 1, c = 2)
Fact(a = 2, b = 1, c = 3)
Fact(a = 2, b = 2, c = 4)
Fact(a = 2, b = 2, c = 5)

I would like to create sub-groups based on the attributes 'a' and 'b'.  My rule should fire three times for the facts listed above, providing the corresponding collection of Fact.

The only solution that I can think of is to build a HashSet and add each Fact to the HashSet using the attributes as keys.  I suppose it would have to be a nested set since I can't define a multi-valued key class within a rule.  I could then handle this HashSet in a RHS block.  However, I realize that I'm completely subverting the whole rule language…

Any suggestions?

Thanks,

Mike

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