2

Drools Expert でルールを記述しようとしています。whenルールの部分では、Applicationオブジェクトのいくつかのプロパティをチェックします。このオブジェクトにはリストが含まれており、このリスト内の SomeOtherType のすべてのオブジェクトに一連のルールが適用されるかどうかを確認したいと思います。ルールは、そのリスト内のすべてのオブジェクトに対して制約が有効な場合にのみ実行する必要があります。

rule "Application eligible"
    when
        app : Application(
               some constrains
               & write some constraints for all objects in app.getList() (a method
               that returns a List<SomeOtherType> object)
        )
    then 
        // application is eligible
end
4

2 に答える 2

3

SomeOtherTypeまだ行っていない場合は、すべてのインスタンスもワーキング メモリに挿入します。次に、すべての SomeOtherType の色が RED であることを確認したい場合は、次のようにしてみてください。

rule "Application eligible"
when
    $app : Application()
    forall( $x : SomeOtherType( application == $app ) 
            SomeOtherType( this == $x, color == RED ) )
then 
    // application is eligible
end
于 2011-02-26T16:17:22.910 に答える
3

また、Geoffry が提案したように、collect を使用してオブジェクトを作業メモリに挿入しなければならないことを回避したい場合は、これを行うための別の種類のハックな方法を見つけました。

rule "Person has all brothers"
  when
    $person : Person(siblings != null, siblings.size > 0) 
    List(size == siblings.size) from collect (Person(sex != null, sex == "m") from $person.siblings)
  then
    #Person has all brothers
  end
于 2014-07-21T12:15:46.277 に答える