gpt4 book ai didi

java - 使用 insertLogical 时停止进入循环

转载 作者:太空宇宙 更新时间:2023-11-04 13:54:07 24 4
gpt4 key购买 nike

我在 drools 中使用 insertLogical()。

规则如下:

rule "logical insert"
salience 100
when
$p : Person( $number : number > 1, $name : name == "AB" || name == "AC" )
not ( exists( PersonConfig( person == $p )))
then
System.out.println("Inserted PC");
insertLogical(new PersonConfig(16,$name,$p));
end

rule "Check Inserted"
salience 90
when
$pc : PersonConfig( )
then
System.out.println("Inserted PC Object: "+$pc);
end

rule "Retract Person Config Rule When Clause"
salience 80
when
$p : Person( number > 1, name == "AB" || name == "AC" )
then
System.out.println("Retracting : "+$p);
//$p.setName("BD");
//retract($p);
update($p);
end

rule "Checking Person Config Exist"
salience 70
when
not ( exists( PersonConfig( ) ))
then
System.out.println("PC not Exists");
end

我在下面尝试做的事情:

  1. 我正在选择所有插入的人员类对象,并在此基础上尝试根据某些条件插入逻辑(PersonConfig())对象。
  2. 现在,我正在对 Person 类对象进行一些更新,但完成 insertLogical 的条件保持不变。这会导致触发“逻辑插入”规则。然后我尝试通过设置以下条件来施加约束来阻止此触发

    not (exists( PersonConfig( person == $p )))

即如果不存在具有相同人员引用的属性的 PersonConfig 对象。但它不起作用。

请检查并提供一些解决方案。

谢谢

最佳答案

通过@PropertyReactive注解;它按照我的预期工作。它不会重新激活规则“逻辑插入”并且不会进入循环。

关于java - 使用 insertLogical 时停止进入循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30013925/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com