It'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 "Number of cases with particular symptom observed"<br>
dialect "mvel"<br>
when<br>
#conditions<br>
Symptom( $sn : name, $snc numCases )<br>
MaxSymptom( numCases < $nc )<br>
then<br> ...<br><br>-W<br><br><div class="gmail_quote">On 25 June 2010 12:43, Dobedani <span dir="ltr"><<a href="mailto:dobedani@gmx.net">dobedani@gmx.net</a>></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'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'm trying<br>
to check whether (1) the HashMap'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 "actions" 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'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<String, Integer>();<br>
ksession.setGlobal("maxSymptoms", 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("fever", 20);<br>
map.put("diarrhoea", 30);<br>
}<br>
}<br>
<br>
rule "Initialisation"<br>
salience 100<br>
when<br>
eval(true); // always!<br>
then<br>
prepareMap(maxSymptoms);<br>
end<br>
<br>
rule "Number of cases with particular symptom observed"<br>
dialect "mvel"<br>
<br>
when<br>
#conditions<br>
Symptom( symptomName : name );<br>
eval(maxSymptoms.keySet() contains symptomName);<br>
#Symptom( numCases > maxSymptoms[symptomName] );<br>
then<br>
#actions<br>
System.out.println(maxSymptoms.keySet() contains symptomName);<br>
System.out.println( maxSymptoms[symptomName] );<br>
#System.out.println("Number of cases with " + symptomName + "<br>
exceeds maximum ")<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>