You should really consider creating a proper fact class for your fact,
instead of using maps... rules will not be clear using maps.
Anyway, I did not tested, but the following should work in case you
really want to use the maps, but again, it is a good practice:
when
$map : Map()
Number( $t1: intValue ) from accumulate(
Map.Entry( key in ("301", "302, "303"), $v :
value ) from
$map.entrySet(),
sum( $v ) )
Number( $t2: intValue > 0 ) from accumulate(
Map.Entry( key in ("301", "302, "303"), $v :
value > 0 )
from $map.entrySet(),
count( $v ) )
eval( ( $t1/$t2 > 1 ) && ($t1/$t2 < 10 ) )
then
...
end
[]s
Edson
2008/4/9 Gerald Cantor <geraldmcantor(a)yahoo.com>:
I have a Map in working memory. The Map has Strings as keys and Integers
as
values. It has 7 keys (REG301, REG302, ... REG307). I'm looking for a way
to
incorporate the following into the LHS of a rule:
For keys 301, 302, 303, compute the total of the Integer values (total 1)
For keys 301, 302, 303, compute the number of keys that have greater than
0
values (total 2)
Divide total 1 by total 2 (if total 2 > 0) and check against a range
For keys 304, 305, 306, 307, compute the total of the Integer values
(total
3)
For keys 304, 305, 306, 307, compute the number of keys that have greater
than 0 values (total 4)
Divide total 3 by total 4 (if total 4 > 0) and check against a range
I have not seen a way to collect / sum over select Map elements.
Any insight as to how I would compute the above totals using collect / sum
would be very much appreciated.
Thanks in advance,
Gerald
--
View this message in context:
http://www.nabble.com/Working-with-Maps-tp16597566p16597566.html
Sent from the drools - user mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
JBoss Drools Core Development
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @
www.jboss.com