使用相应的'不存在'在drools积累

时间:2017-09-27 11:27:09

标签: java drools exists accumulate

我的问题是关于使用“不存在”的等价物。在Drools积累函数中构造。

我使用了以下规则部分的Performance对象的简单累积,它可以很好地编译并产生预期的结果:

rule "rule-conflicting-code-set-1" 
...
when
...
    $conflicts : List(size() > 1) 
            from accumulate( 
                $p : Performance(code == "FOO", /*other conditions*/)  
                from $patient.performances,
                collectList($p)) 

then
...
end

现在我想用额外的条件扩展规则。我想阻止累积满足特定条件的表演(即最终在$ conflict列表中)。

新条件是:我不想累积效果,其中存在包含该效果的注意注意是一个包含 performanceSet 字段的对象,该字段包含效果类型的对象(设置performanceSet;)。我创建 thisPerformance()作为效果的方法,作为引用 $ p 的方式。

条件本身看起来像这样:

not exists Attention(performanceSet contains thisPerformance())

我试着像这样重写相应的累积:

$conflicts : List(size() > 1) 
        from accumulate( 
            $p : Performance(
                       code == "FOO", 
                       not exists Attention(performanceSet contains 
                           thisPerformance()),
                       /*other conditions*/)  
            from $patient.performances,
            collectList($p)) 

编译器抱怨'存在' keyword: [ERR 102]第50:40行不匹配的输入'存在'在规则" rule-conflicting-code-set-1"。 Parser返回了一个null包。

我怀疑我的问题的解决方案看起来会有很大不同,但让这个例子作为我想要实现的解释。

1 个答案:

答案 0 :(得分:0)

not exists不是Drools中的有效构造。只需使用not代替。

然后,你要找的是在累积中使用多个模式。您需要将规则重写为以下内容:

$conflicts : List(size() > 1) 
    from accumulate( 
        ($p : Performance(code == "FOO") from $patient.performances and
        not Attention(performanceSet contains $p)),
        collectList($p)) 

希望它有所帮助,