|
I am new to Drools 3. My DRL dile is compiled and the test program runs well, however, the result is NOT my expectation. According to the input, it should output "Result = error1", but it print NOTHING.
It works if I change lines <1> and <2> of the drl file to: ICoverage(healthPlan!="plan2"). So I guess the problem should come from "RuleParam(p:healthPlan)". I have checked the documentation of Drools 3 and the testing code in http://anonsvn.labs.jboss.com/labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/not_with_bindings_rule_test.drl. But I didn't find out the reason. Does anybody know why? The following is my source code that runs on Drools3 RC2. Thanks a lot. Liang =========================================================================================== My drl file: ------------------------------------------------------------------------------------------- package gov.sc.eip.rules; #generated from Decision Table import java.lang.String; import gov.sc.eip.model.ICoverage; import gov.sc.eip.helper.IConstants; import gov.sc.eip.rules.test.RuleParam; #From row number: 14 rule "HealthRules_14" salience 65522 when RuleParam(changeReason=="MA") || RuleParam(changeReason=="CM") RuleParam(healthPlan!="blank") && RuleParam(healthPlan!="refused") <1> RuleParam(p:healthPlan) <2> ICoverage(healthPlan!=p) then System.out.println("result = " + "error1"); end ---------------------------------------- drl end ------------------------------------------ Snippet of Test program ------------------------------------------------------------------------------------------- ICoverage coverage = new Coverage(); //paremeter RuleParam params = new RuleParam(); params.setChangeReason("MA"); params.setHealthPlan("plan2"); //ICoverage object coverage.setHealthPlan("plan1"); t.engine = t.ruleBase.newWorkingMemory(); t.engine.assertObject(params); t.engine.assertObject(coverage); t.engine.fireAllRules(); --------------------------------------------------------------------------------------------- |
|
try:
when RuleParam(changeReason=="MA") || RuleParam(changeReason=="CM") RuleParam(p:healthPlan!="blank") && RuleParam(healthPlan!="refused") ICoverage(healthPlan != p) then System.out.println("result = " + p); On 4/16/06, Liang Gao <[hidden email]> wrote: > > I am new to Drools 3. My DRL dile is compiled and the test program runs > well, however, the result is NOT my expectation. According to the input, it > should output "Result = error1", but it print NOTHING. > > It works if I change lines <1> and <2> of the drl file to: > ICoverage(healthPlan!="plan2"). So I guess the problem should come from > "RuleParam(p:healthPlan)". I have checked the documentation of Drools 3 and > the testing code in > http://anonsvn.labs.jboss.com/labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/not_with_bindings_rule_test.drl. But > I didn't find out the reason. > > Does anybody know why? The following is my source code that runs on > Drools3 RC2. > > Thanks a lot. > > Liang > > > =========================================================================================== > > My drl file: > > ------------------------------------------------------------------------------------------- > package gov.sc.eip.rules; > #generated from Decision Table > import java.lang.String; > import gov.sc.eip.model.ICoverage; > import gov.sc.eip.helper.IConstants; > import gov.sc.eip.rules.test.RuleParam; > > #From row number: 14 > rule "HealthRules_14" > > salience 65522 > when > RuleParam(changeReason=="MA") || > RuleParam(changeReason=="CM") > RuleParam(healthPlan!="blank") && > RuleParam(healthPlan!="refused") > <1> RuleParam(p:healthPlan) > <2> ICoverage(healthPlan!=p) > then > System.out.println("result = " + "error1"); > end > ---------------------------------------- drl end > ------------------------------------------ > > Snippet of Test program > > ------------------------------------------------------------------------------------------- > ICoverage coverage = new Coverage(); > > //paremeter > RuleParam params = new RuleParam(); > params.setChangeReason("MA"); > params.setHealthPlan("plan2"); > > //ICoverage object > coverage.setHealthPlan("plan1"); > > t.engine = t.ruleBase.newWorkingMemory(); > t.engine.assertObject(params); > t.engine.assertObject(coverage); > > t.engine.fireAllRules(); > > --------------------------------------------------------------------------------------------- > > > > -- Steven Williams Supervising Consultant Object Consulting Office: 8615 4500 Mob: 0439 898 668 Fax: 8615 4501 [hidden email] www.objectconsulting.com.au consulting | development | training | support our experience makes the difference |
|
In reply to this post by Liang Gao
Liang,
As a rule of tumb, you should think about how many instances of objects do you want to match in your rule each time. So, in your sample, if I understood correctly, you want to match each RuleParam object against the rule. This way, you should write only one column for the RuleParam object type. Lets see an example of one possible way to write this rule: rule "HealthRules_14" salience 65522 when RuleParam( $healthPlan : healthPlan!="blank", healthPlan!="refused", $cr : changeReason -> ( $cr.equals("MA") || $cr.equals("CM") ) ) ICoverage(healthPlan != $healthPlan) then System.out.println("result = " + "error1"); end Lets understand the rule: this rule will activate for each pair of RuleParam and ICoverage instances in the working memory that match the constraints: RuleParam column. Any RuleParam instance that match ALL constraints bellow: 1) $healthPlan: healthPlan != "blank" this is a simple literal constraint. We also bound the value of the healthPlan attribute to the $healthPlan variable. Please note that the "$" in the name of the variable is simply a best practice to allow one to easily see where a variable is a bound variable. Any valid java identifier could be used as a variable name. 2) healthPlan != "refused" another simple literal constraint. 3) $cr : changeReason -> ( $cr.equals("MA") || $cr.equals("CM") ) this is a predicate constraint. First we bind the $cr variable to the changeReason attribute, and the we evaluate a java expression that must return "true" or "false". If all above constraints return true, the RuleParam instance is matched and will try a join with all instances of ICoverage in the working memory. The join constraint is: 1) healthPlan != $healthPlan A variable bound constraint that will check if the healthPlan attribute of the ICoverage instance is different from the value of the previously bound variable. If all previously constraints are met, the rule is triggered for that pair of [RuleParam, ICoverage] instances. I hope it helps. If it is not clear, let me know and I try again. :) Regards, Edson ----- Original Message ----- From: "Liang Gao" <[hidden email]> To: <[hidden email]> Sent: Sunday, April 16, 2006 1:37 AM Subject: [drools-user] I need your help!!! > I am new to Drools 3. My DRL dile is compiled and the test program runs well, however, the result is NOT my expectation. According to the input, it should output "Result = error1", but it print NOTHING. > > It works if I change lines <1> and <2> of the drl file to: ICoverage(healthPlan!="plan2"). So I guess the problem should come from "RuleParam(p:healthPlan)". I have checked the documentation of Drools 3 and the testing code in http://anonsvn.labs.jboss.com/labs/jbossrules/trunk/drools-compiler/src/test /resources/org/drools/integrationtests/not_with_bindings_rule_test.drl. But I didn't find out the reason. > > Does anybody know why? The following is my source code that runs on Drools3 RC2. > > Thanks a lot. > > Liang > > ============================================================================ =============== > > My drl file: > -------------------------------------------------------------------------- ----------------- > package gov.sc.eip.rules; > #generated from Decision Table > import java.lang.String; > import gov.sc.eip.model.ICoverage; > import gov.sc.eip.helper.IConstants; > import gov.sc.eip.rules.test.RuleParam; > > #From row number: 14 > rule "HealthRules_14" > > salience 65522 > when > RuleParam(changeReason=="MA") || RuleParam(changeReason=="CM") > RuleParam(healthPlan!="blank") && RuleParam(healthPlan!="refused") > <1> RuleParam(p:healthPlan) > <2> ICoverage(healthPlan!=p) > then > System.out.println("result = " + "error1"); > end > ---------------------------------------- drl > > Snippet of Test program > -------------------------------------------------------------------------- ----------------- > ICoverage coverage = new Coverage(); > > //paremeter > RuleParam params = new RuleParam(); > params.setChangeReason("MA"); > params.setHealthPlan("plan2"); > > //ICoverage object > coverage.setHealthPlan("plan1"); > > t.engine = t.ruleBase.newWorkingMemory(); > t.engine.assertObject(params); > t.engine.assertObject(coverage); > > t.engine.fireAllRules(); > -------------------------------------------------------------------------- > > > ---------------------------------------------------------------------------- ---- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.1.385 / Virus Database: 268.4.1/313 - Release Date: 15/4/2006 |
| Powered by Nabble | Edit this page |
