Re: [rules-users] Best way to write a rule where pattern has multiple constraints
Vincent and Wolfgang, thanks for for clearing things up for me. The first approach is definitely not what we want and I now see how this could potentially cause issues. In fact we'll probably need to re-evaluate how some of our rules are written. - Larry -- View this message in context: http://drools.46999.n3.nabble.com/Best-way-to-write-a-rule-where-pattern-has-multiple-constraints-tp3920532p3920861.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Best way to write a rule where pattern has multiple constraints
Vincent has answered this very well. I'd just like to point out that you might read a verbal interpretation of the conditions to yourself, and judge for yourself. (a) When there is a RuleContect where the billingSystem equals "ABC" and there is a RuleContext where the policyStatus is equals "active" and there is a RuleContext where a renewalDueDate is given then... (b) When there is a RuleContect where the billingSystem equals "ABC" and the policyStatus is equals "active" and a renewalDueDate is given then... -W On 18/04/2012, larryc wrote: > I was reviewing some of our DRLs and noticed some rules written like this: > > when >RuleContext(billingSystem == "ABC") >RuleContext(policyStatus == "active") >RuleContext(renewalDueDate != null) > then ... > > while others were written this way: > > when >RuleContext(billingSystem == "ABC", policyStatus == "active", > renewalDueDate != null) > then ... > > There should only be one RuleContext fact in the knowledge base at one time. > Which approach is better? Is one approach more efficient for Drools than > the other? Does it matter? > > Thanks! > > -- > View this message in context: > http://drools.46999.n3.nabble.com/Best-way-to-write-a-rule-where-pattern-has-multiple-constraints-tp3920532p3920532.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Best way to write a rule where pattern has multiple constraints
First approach is more like a quick-n-dirty trick. It only works if you are sure that only one RuleContext exists in the working memory. If not ... the rule will lead to really strange results ... The real question is why you have rules like that, what was the initial justification? To me it seems to be a mistake, written by someone that did not understand well inferences systems, who has fixed his bugs by restricting to one single RuleContext object... or may be not even ask hilmself the question if this was a initial constraint to have one single object. The second approach is the correct one because : - You want to test one single objet --> You write one single pattern. Using two patterns means (in common sens of everybody writing rules) matching two objects ... - If you give more than one RuleContext, it will still work Does it matter? Not sure that it will change perfs for one single object in WM, but it is the correct way to do, so yes (to me). At least, add a test in all you first rule's pattern to test a common identifier or the object's reference (to ensure that this is the same object), but it will remain a trick (safer, but still not clear) - Mail original - De: "larryc" À: rules-users@lists.jboss.org Envoyé: Mercredi 18 Avril 2012 18:15:09 Objet: [rules-users] Best way to write a rule where pattern has multiple constraints I was reviewing some of our DRLs and noticed some rules written like this: when RuleContext(billingSystem == "ABC") RuleContext(policyStatus == "active") RuleContext(renewalDueDate != null) then ... while others were written this way: when RuleContext(billingSystem == "ABC", policyStatus == "active", renewalDueDate != null) then ... There should only be one RuleContext fact in the knowledge base at one time. Which approach is better? Is one approach more efficient for Drools than the other? Does it matter? Thanks! -- View this message in context: http://drools.46999.n3.nabble.com/Best-way-to-write-a-rule-where-pattern-has-multiple-constraints-tp3920532p3920532.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users