[rules-users] Looking up values in WHEN block
Wolfgang Laun
wolfgang.laun at gmail.com
Fri Jun 25 07:32:16 EDT 2010
It's generally not a good idea to use globals in rules.
I suggest that you use a simple
class MaxSymptoms {
On 25 June 2010 12:43, Dobedani <dobedani at gmx.net> wrote:
>
> Dear All,
>
> I'm trying to develop rules which will help to analyse incoming reports of
> disease related symptoms. I have found a way to fill a HashMap with maximum
> allowable values specific for various symptoms. I would like to lookup the
> relevant value any time a symptom comes in. In the first place, I'm trying
> to check whether (1) the HashMap's keySet contains the found symptom i.e.
> in
> the WHEN block - but it does not work as expected. Let alone (2) that I can
> lookup the maximum allowable value and check whether it has been exceeded!
> It is strange to me that the result of both "actions" can however be
> printed
> out in the THEN block. How to do this? Any help will be appreciated.
>
> Kind regards, Dobedani
>
>
> Here's some of my Java code:
> public class Symptom {
> private String name;
> private String location;
> private int period;
> private int numCases;
>
> // getters and setters ...
> }
>
> And:
> KnowledgeBase kbase = readKnowledgeBase();
> StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
> java.util.Map maxSymptoms = new java.util.HashMap<String, Integer>();
> ksession.setGlobal("maxSymptoms", maxSymptoms);
>
> Now, some of the code from my DRL file:
> import Symptom;
> global java.util.Map maxSymptoms;
>
> function void prepareMap(java.util.Map map) {
> if (map.size() == 0) {
> map.put("fever", 20);
> map.put("diarrhoea", 30);
> }
> }
>
> rule "Initialisation"
> salience 100
> when
> eval(true); // always!
> then
> prepareMap(maxSymptoms);
> end
>
> rule "Number of cases with particular symptom observed"
> dialect "mvel"
>
> when
> #conditions
> Symptom( symptomName : name );
> eval(maxSymptoms.keySet() contains symptomName);
> #Symptom( numCases > maxSymptoms[symptomName] );
> then
> #actions
> System.out.println(maxSymptoms.keySet() contains symptomName);
> System.out.println( maxSymptoms[symptomName] );
> #System.out.println("Number of cases with " + symptomName + "
> exceeds maximum ")
> end
>
>
> --
> View this message in context:
> http://drools-java-rules-engine.46999.n3.nabble.com/Looking-up-values-in-WHEN-block-tp921790p921790.html
> Sent from the Drools - User mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100625/6afbb763/attachment.html
More information about the rules-users
mailing list