Drools 决策表规则不使用更新值

发布于 2024-10-19 02:01:18 字数 796 浏览 3 评论 0原文

我正在使用 Drools Rules Server 作为服务。我们正在使用一个决策表,

Pre Rules Movie Object:  
actor: "unknown"  
movie: "Ghostbusters"  
rating: 9

我在 Drools 决策表中有 2 个简单的规则。第一条规则检查值 (movie=="Ghostbusters"),然后设置对象 setActor("Bill Murray") 的调用。

第二条规则检查 Actor 是什么。我在第二条规则中有两行。 如果 Actor == "Bill Murray" 它会调用 setRating(10) 操作。如果 actor == "unknown" setRating(8)

第一条规则按预期触发,我可以 printLn getActor 显示它是“ Bill Murray”,但在第二条规则中,actor == “unknown” 操作始终会触发。即使在该行中我打印 getActor 它也会打印“Bill Murray”,但它使用“未知”规则。

当对象从规则返回时,它具有 Actor = Bill Murray 以及规则中设置的所有值“正确”,但规则似乎始终使用我在评估规则时在规则之外创建的原始对象。

我是否需要添加一些内容到决策表或调用 drools 规则服务器以“更新”规则表之间的对象?

I am using Drools Rules Server as a service. We are using a decision table

Pre Rules Movie Object:  
actor: "unknown"  
movie: "Ghostbusters"  
rating: 9

I have 2 simple rules in a Drools Decision table. The 1st rule checks for a value (movie=="Ghostbusters") and then sets the calls that objects setActor("Bill Murray").

The 2nd rule checks to see what the Actor is. I have 2 rows in this second rule. if Actor == "Bill Murray" it calls an action of setRating(10). And if actor == "unknown" setRating(8)

The first rule fires as expected, and I can printLn the getActor to show it's "Bill Murray" but in the second rule, the actor == "unknown" action always fires. Even if in that row I print getActor it prints "Bill Murray" but it's using the "unknown" rule.

When the object comes back from the rules, it has Actor = Bill Murray and all values set in the rule "correct" but the rules seem to always use the original object I created outside the rule when evaluating rules.

Is there something I have to add to the decision table or the call to invoke the drools rule server to "update" the object between rule tables?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执笔绘流年 2024-10-26 02:01:18

我知道自从您提出问题以来已经过去了太多时间,但对于其他有同样问题的人来说:
如前所述,您应该修改对象而不是设置它。要在决策表中执行此操作,请在 RuleTable 中添加一个操作列,并在第二行中添加:

modify($className){ setActor("Bill Murray")};

将操作下的第一行保留为空白。

I know too much time has passed since you asked the question but for others with the same problem:
As stated you should modify the object and not set it. To do this in decision tables add an action column in your RuleTable and in second line you should add:

modify($className){ setActor("Bill Murray")};

Keep the first row under action blank.

烟凡古楼 2024-10-26 02:01:18

您应该使用 Drools 文档(4.8.4.1、4.8.4.2)中所述的 updatemodify 方法:

rule "modify stilton"
when
    $stilton : Cheese(type == "stilton")
then
    modify( $stilton ){
        setPrice( 20 ),
        setAge( "overripe" )
    }
end

这将告诉引擎对象已更改并且规则将被更改重新申请。

you should use update or modify method as described in Drools docs (4.8.4.1, 4.8.4.2):

rule "modify stilton"
when
    $stilton : Cheese(type == "stilton")
then
    modify( $stilton ){
        setPrice( 20 ),
        setAge( "overripe" )
    }
end

this will tell the engine that object has been changed and rules will be reapplied.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文