Nested Rules In Drools

别来无恙 提交于 2019-12-08 13:03:44

问题


I have a .drl file which contains more than 100 rules. There are approximately 40 rules like rule "1", some 35 like rule "2" and rest are like rule "3".

rule "1"
    when
        m: MyBeanClass( something1 == "train" && something2 == somevalue2)
    then
        m.setSomeThing(someOtherValue);
        update(m);
    end

rule "2"
    when
        m: MyBeanClass( something1 == "bus" && something2 == somevalue2)
    then
        m.setSomeThing(someOtherValue);
        update(m);
    end

rule "3"
    when
        m: MyBeanClass( something1 == "car" && something2 == somevalue2)
    then
        m.setSomeThing(someOtherValue);
        update(m);
    end

On firing all rules, all the rules will get executed, which I do not want. If "something1" is not equal to "train", then I want the execution flow to directly go to the 41st rule which is like the rule "2" here.

Please suggest.

Thanks, Shardul


回答1:


I'd have three scoping rules for "car", "bus", and "train" to set a value, then 41 rule took in that scoped value and operated on it.

You still have to write 44 rules, but you don't have to repeat the 41 for each scoping case.



来源:https://stackoverflow.com/questions/17260675/nested-rules-in-drools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!