It&#39;s generally not a good idea to use globals in rules.<br><br>I suggest that you use a simple<br>  class MaxSymptom {<br>    String name;<br>    int numCases;<br>  }<br><br>and create facts according to that map. Then you can write your rule<br>
<br>rule &quot;Number of cases with particular symptom observed&quot;<br>
    dialect &quot;mvel&quot;<br>
    when<br>
        #conditions<br>
        Symptom( $sn : name,  $snc numCases )<br>
        MaxSymptom( numCases &lt; $nc )<br>
    then<br>    ...<br><br>-W<br><br><div class="gmail_quote">On 25 June 2010 12:43, Dobedani <span dir="ltr">&lt;<a href="mailto:dobedani@gmx.net">dobedani@gmx.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Dear All,<br>
<br>
I&#39;m trying to develop rules which will help to analyse incoming reports of<br>
disease related symptoms. I have found a way to fill a HashMap with maximum<br>
allowable values specific for various symptoms. I would like to lookup the<br>
relevant value any time a symptom comes in. In the first place, I&#39;m trying<br>
to check whether (1) the HashMap&#39;s keySet contains the found symptom i.e. in<br>
the WHEN block - but it does not work as expected. Let alone (2) that I can<br>
lookup the maximum allowable value and check whether it has been exceeded!<br>
It is strange to me that the result of both &quot;actions&quot; can however be printed<br>
out in the THEN block. How to do this? Any help will be appreciated.<br>
<br>
Kind regards, Dobedani<br>
<br>
<br>
Here&#39;s some of my Java code:<br>
public class Symptom {<br>
    private String name;<br>
    private String location;<br>
    private int period;<br>
    private int numCases;<br>
<br>
    // getters and setters ...<br>
}<br>
<br>
And:<br>
KnowledgeBase kbase = readKnowledgeBase();<br>
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();<br>
java.util.Map maxSymptoms = new java.util.HashMap&lt;String, Integer&gt;();<br>
ksession.setGlobal(&quot;maxSymptoms&quot;, maxSymptoms);<br>
<br>
Now, some of the code from my DRL file:<br>
import Symptom;<br>
global java.util.Map maxSymptoms;<br>
<br>
function void prepareMap(java.util.Map map) {<br>
    if (map.size() == 0) {<br>
        map.put(&quot;fever&quot;, 20);<br>
        map.put(&quot;diarrhoea&quot;, 30);<br>
    }<br>
}<br>
<br>
rule &quot;Initialisation&quot;<br>
    salience 100<br>
    when<br>
        eval(true);  // always!<br>
    then<br>
        prepareMap(maxSymptoms);<br>
end<br>
<br>
rule &quot;Number of cases with particular symptom observed&quot;<br>
    dialect &quot;mvel&quot;<br>
<br>
    when<br>
        #conditions<br>
        Symptom( symptomName : name );<br>
        eval(maxSymptoms.keySet() contains symptomName);<br>
        #Symptom( numCases &gt; maxSymptoms[symptomName] );<br>
    then<br>
        #actions<br>
        System.out.println(maxSymptoms.keySet() contains symptomName);<br>
        System.out.println( maxSymptoms[symptomName] );<br>
        #System.out.println(&quot;Number of cases with &quot; + symptomName + &quot;<br>
exceeds maximum &quot;)<br>
end<br>
<font color="#888888"><br>
<br>
--<br>
View this message in context: <a href="http://drools-java-rules-engine.46999.n3.nabble.com/Looking-up-values-in-WHEN-block-tp921790p921790.html" target="_blank">http://drools-java-rules-engine.46999.n3.nabble.com/Looking-up-values-in-WHEN-block-tp921790p921790.html</a><br>

Sent from the Drools - User mailing list archive at Nabble.com.<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>