2017-09-27 117 views
1

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

我使用性能对象的简单堆积与编译罚款,并产生预期的结果如下规则部分:

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 

现在我想用一个额外的条件延长规则。我想阻止满足一定条件的演出积累(即最终在$冲突列表中)。

新的条件是:我不想积攒其中存在一个注意包含性能性能注意是一个对象,其中performanceSet字段保存类型的对象性能(Set 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)) 

编译器抱怨有 '存在' 关键字:[ERR 102 ]规则“rule-conflicting-code-set-1”中的行50:40不匹配输入'exists'。解析器返回一个空包。

我怀疑我的问题的解决方案看起来有很大的不同,但让我们来举例说明我想达到的目标。

回答

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)) 

希望它能帮助,

+0

这正是我一直在寻找的语法!非常感谢! – Edvaaart