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