Where can I see if a pattern failed in rule?

一曲冷凌霜 提交于 2019-12-13 04:36:09

问题


I run a rule that contains a few patterns, I want to know which pattern failed:

I've tried to debug the code (drools 7.18.0), and didn't found the relevant place.

rule example:

rule "Trigger"
agenda-group "Trigger"
salience 100
    when
        $pcase : PCaseMgr()

        D1($id: id, type != null, type == "AAA")
        D2(aId == $id)

    then
        $pcase.printAnalyticsRuleLog(">>>>>>>>>>>>>>>>>>> In Trigger");
end

in the example above, if D1 pattern is passed, and D2 pattern is failed, where in the code (of drools 7.18.0) can i see if the pattern was failed?


回答1:


You can't. Because of the algorithm Drools uses internally, patterns are decomposed into nodes and nodes can be shared among multiple rules in your knowledge base. If you really need to know why a rule was not fire, then you can create other rules that will tell you that. In your example, you could create something like this:

rule "No Trigger because of No D2"
agenda-group "Trigger"
salience 100
    when
        $pcase : PCaseMgr()

        D1($id: id, type != null, type == "AAA")
        not D2(aId == $id)

    then
        $pcase.printAnalyticsRuleLog(">>>>>>>>>>>>>>>>>>> No Trigger because no D2");
end

Hope it helps,



来源:https://stackoverflow.com/questions/57593723/where-can-i-see-if-a-pattern-failed-in-rule

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