Java 检查列表的所有元素(Drools专家)
我在试着用Drools Expert写规则。在规则的when部分,我检查了应用程序对象的一些属性。这个对象包含一个列表,我想检查一组规则是否适用于这个列表中其他类型的所有对象。只有当约束对该列表中的所有对象有效时,才应触发该规则Java 检查列表的所有元素(Drools专家),java,rules,drools,decision-tree,rule-engine,Java,Rules,Drools,Decision Tree,Rule Engine,我在试着用Drools Expert写规则。在规则的when部分,我检查了应用程序对象的一些属性。这个对象包含一个列表,我想检查一组规则是否适用于这个列表中其他类型的所有对象。只有当约束对该列表中的所有对象有效时,才应触发该规则 rule "Application eligible" when app : Application( some constrains & write some constrai
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
如果尚未将所有SomeOtherType实例插入工作内存,请将其插入工作内存。
如果要检查所有其他类型的颜色是否为红色,请尝试以下操作:
rule "Application eligible"
when
$app : Application()
forall( $x : SomeOtherType( application == $app )
SomeOtherType( this == $x, color == RED ) )
then
// application is eligible
end
如果尚未将所有SomeOtherType实例插入工作内存,请将其插入工作内存。
如果要检查所有其他类型的颜色是否为红色,请尝试以下操作:
rule "Application eligible"
when
$app : Application()
forall( $x : SomeOtherType( application == $app )
SomeOtherType( this == $x, color == RED ) )
then
// application is eligible
end
我还发现了另一种破解方法,如果你想避开必须使用collect将对象插入工作内存的问题,就像Geoffry建议的那样:
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
我还发现了另一种破解方法,如果你想避开必须使用collect将对象插入工作内存的问题,就像Geoffry建议的那样:
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
不将所有SomeOtherType实例安装到工作内存中是否可能?例如,将forall与from一起使用?是的,但from开始向后链接,而不是向前链接IIRC,这可能会对性能产生影响请参阅手册。还有其他一些有趣的关键字可以使用,比如collect IIRC也可以参阅手册。在SomeOtherType应用程序==$app中,应用程序意味着什么?也许你是指申请@是否可以不将所有SomeOtherType实例安装到工作内存中?例如,将forall与from一起使用?是的,但from开始向后链接,而不是向前链接IIRC,这可能会对性能产生影响请参阅手册。还有其他一些有趣的关键字可以使用,比如collect IIRC也可以参阅手册。在SomeOtherType应用程序==$app中,应用程序意味着什么?也许你是指申请@史密特:为什么这是一种恶作剧的方式?为什么这是一种恶作剧的方式?