1

我正在尝试编写避免排序的规则。我的情况是——

rule "common rule"
when
 // check if it is a "xyz" customer
then
  insertLogical(new MyCondition("Is a xyz customer", true));
end

在其他规则中,我根据上述条件做出决定——

rule "rule1"
when
 MyCondition("Is a xyz customer", true)
then
 System.out.println("This is a xyz customer");
end

我还有一条规则——

rule "rule2"
when
 not MyCondition("Is a xyz customer", true)
then
 System.out.println("This is NOT a xyz customer");
end

由于我没有使用任何航行,在某些情况下,我的规则 1 和规则 2 都被解雇了。最初,知识库中没有 MyCondition 对象,“rule2”被触发。稍后,将插入 MyCondition 的对象并触发“rule1”。

1. 当我没有检查“不”条件的规则时,一切正常。当我使用“不”存在条件时,我遇到了问题。有什么方法可以克服这个问题?

4

1 回答 1

1

"I am trying to write rules avoiding ordering"

It sounds like you need to order your rules using salience in order to get the desired behavior.

I suggest that you use a higher salience on the rule(s) that insert a "MyCondition" fact than the rules that check for the presence or absence of a "MyCondition" fact.

For example:

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

于 2013-06-24T18:37:46.527 回答