在Drools中编写规则而不使用sailence--不存在检查
我正在尝试编写避免排序的规则。我的情况是--在Drools中编写规则而不使用sailence--不存在检查,drools,Drools,我正在尝试编写避免排序的规则。我的情况是-- rule "common rule" when // check if it is a "xyz" customer then insertLogical(new MyCondition("Is a xyz customer", true)); end 在其他规则中,我根据上述条件做出决定-- 我还有一条规则-- 由于我没有使用任何sailence,在某些情况下,我的规则1和规则2都会被解雇。最初,knowledgebase中没有MyCond
rule "common rule"
when
// check if it is a "xyz" customer
then
insertLogical(new MyCondition("Is a xyz customer", true));
end
在其他规则中,我根据上述条件做出决定--
我还有一条规则--
由于我没有使用任何sailence,在某些情况下,我的规则1和规则2都会被解雇。最初,knowledgebase中没有MyCondition对象,“rule2”将被触发。稍后,将插入MyCondition的对象,并触发“规则1”
1。当我没有检查“不”条件的规则时,一切都很完美。我在使用“not”条件时遇到问题。克服这一问题的方法是什么?
“我正在尝试编写规则以避免排序”
听起来你需要使用显著性来排序规则,以获得所需的行为
我建议您在插入“MyCondition”事实的规则上使用比检查是否存在“MyCondition”事实的规则更高的显著性
例如:
rule "common rule"
salience 10
when
// check if it is a "xyz" customer
then
insertLogical(new MyCondition("Is a xyz customer", true));
end
规则“规则2”
显著性0
什么时候
非MyCondition(“是xyz客户”,对)
然后
System.out.println(“这不是xyz客户”);
结束
“我正在尝试编写规则以避免排序”
听起来你需要使用显著性来排序规则,以获得所需的行为
我建议您在插入“MyCondition”事实的规则上使用比检查是否存在“MyCondition”事实的规则更高的显著性
例如:
rule "common rule"
salience 10
when
// check if it is a "xyz" customer
then
insertLogical(new MyCondition("Is a xyz customer", true));
end
规则“规则2”
显著性0
什么时候
非MyCondition(“是xyz客户”,对)
然后
System.out.println(“这不是xyz客户”);
结束
谢谢mikedev9000的回答。当然,使用显著性是解决方案之一。我对不使用显著性的解决方案更感兴趣。编写模块化和可重用规则的最佳实践是什么?感谢mikedev9000的回答。当然,使用显著性是解决方案之一。我对不使用显著性的解决方案更感兴趣。编写模块化和可重用规则的最佳实践是什么?您有没有找到更好的方法来解决这个问题?我很想听听其他不依赖显著性的解决方案。你有没有找到更好的方法来解决这个问题?我很想听听其他不依赖显著性的解决方案。
rule "common rule"
salience 10
when
// check if it is a "xyz" customer
then
insertLogical(new MyCondition("Is a xyz customer", true));
end
rule "rule1"
salience 0
when
MyCondition("Is a xyz customer", true)
then
System.out.println("This is a xyz customer");
end
rule "rule2"
salience 0
when
not MyCondition("Is a xyz customer", true)
then
System.out.println("This is NOT a xyz customer");
end