流口水无限循环

发布于 2025-01-25 05:48:01 字数 463 浏览 2 评论 0原文

我是流口水的新手。 有人可以告诉为什么尽管没有子句,为什么该规则陷入了无限循环?

declare InvalidPersonalInfoRequest
    request: PersonalInfo
    msg: String
end

rule "validate first name"
  dialect "java"
  when
    $r: PersonalInfo( firstName == null || firstName == '')
    not ( InvalidPersonalInfoRequest( this.request == $r) )
  then
    String msg = "invalid  name";
    System.out.println( msg );
    insertLogical( new InvalidPersonalInfoRequest($r, msg) );
end

I am new to Drools.
Can someone tell why this rule is running into infinite loop despite not clause ?

declare InvalidPersonalInfoRequest
    request: PersonalInfo
    msg: String
end

rule "validate first name"
  dialect "java"
  when
    $r: PersonalInfo( firstName == null || firstName == '')
    not ( InvalidPersonalInfoRequest( this.request == $r) )
  then
    String msg = "invalid  name";
    System.out.println( msg );
    insertLogical( new InvalidPersonalInfoRequest($r, msg) );
end

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

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

发布评论

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

评论(1

︶ ̄淡然 2025-02-01 05:48:02

这是因为您正在使用insertlogical而不是insert

From the Drools documentation:

使用陈述或逻辑插入的Drools Engine插入事实:

  • 说明插入:用insert()定义。列出插入后,通常会明确撤回事实。 (一般使用时插入一词是指插入。)

  • 逻辑插入:用insertLogical()定义。逻辑插入后,当插入事实的规则中的条件不再正确时,插入的事实会自动撤回。当没有条件支持逻辑插入时,事实会撤回。从逻辑上插入的事实被认为是由流口引擎证明是合理的。

当您使用插入术时,当触发条件停止到真时,将插入的对象从内存中删除。由于您的插入立即否定了条件,因此立即将其从内存中删除。

交换到插入以按照您的预期工作。

It's because you're using insertLogical instead of insert.

From the Drools documentation:

The Drools engine inserts facts using either stated or logical insertions:

  • Stated insertions: Defined with insert(). After stated insertions, facts are generally retracted explicitly. (The term insertion, when used generically, refers to stated insertion.)

  • Logical insertions: Defined with insertLogical(). After logical insertions, the facts that were inserted are automatically retracted when the conditions in the rules that inserted the facts are no longer true. The facts are retracted when no condition supports the logical insertion. A fact that is logically inserted is considered to be justified by the Drools engine.

When you use insertLogical, the inserted object is removed from memory when the triggering condition stops being true. Since your insertion immediately negates the condition, it's immediately removed from memory.

Swap over to insert to work as you expect.

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