与姐姐 类 一起使用 'or' 时出现 Drools 错误

Drools Error when using 'or' with sister classes

我在编写规则并尝试 'or' 姐姐 classes 时 运行 遇到了一个小问题。一些背景,这都是一个小模型来演示,这是在6.4中。我有一个父 class 事实,它有两个女儿:ChildAFact 和 ChildBFact,我有这个规则:

rule "Rule 1"
when
    f:      ( ChildAFact() or ChildBFact() )
then
    System.out.println(f);
end

当我 运行 我的测试时,我得到这个错误:

java.lang.RuntimeException: Error while creating KieBase[Message [id=1, level=ERROR, path=Sample.drl, line=12, column=0
   text=Duplicate declaration for variable 'f' in the rule 'Rule 1'], Message [id=2, level=ERROR, path=Sample.drl, line=10, column=0
   text=Unable to Analyse Expression System.out.println(f);:
[Error: unable to resolve method using strict-mode: org.drools.core.spi.KnowledgeHelper.f()]
[Near : {... System.out.println(f); ....}]
                                ^
[Line: 10, Column: 0]]]
    at org.drools.compiler.kie.builder.impl.KieContainerImpl.getKieBase(KieContainerImpl.java:450)
    at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:604)
    at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:575)
    at com.sample.DroolsTest.main(DroolsTest.java:20)

我希望有人知道解决这个问题的方法。我希望符合条件的对象将被转换为 'ored'

对象的最近共同祖先

不可能将一个变量绑定到两种不同的类型。但你可能会过得去

rule "a or b"
when
    f: Fact( class == ChildAFact.class || == ChildBFact.class )
then
    System.out.println(f);
end

此类规则的用途受到限制。一般来说,您应该编写单独的规则,每个事实类型一个。您可以使用 "extend" 分解出公共部分,这样您就不必重复所有约束。