用于从 ILOG 中的集合中的对象设置变量的等效 Drools 语法

Equivalent Drools syntax for setting a variable from an object within a collection in ILOG

在我们的 ILOG 规则 irl 文件中,我们多次出现从集合中设置一个变量并从集合中设置另一个不等于第一个对象的变量

student1: com.company.bom.Student() in all_students;
student2: com.company.bom.Student(!(?this.equals(student2))) in all_students;

在 ILOG 中,这些行是否只是 return 集合中的第一个和第二个对象?

以下是在 Drools 中的 drl 规则文件中执行相同操作的最佳方法吗?

student1: com.company.bom.Student() from all_students.get(0);
student2: com.company.bom.Student() from all_students.get(1);

你应该可以检查你的 ILOG 做了什么,所以我只是回答 Drools 部分。

在 Drools 中,可以使用 from <expression> 从触手可及的集合中获取对象。因此,你确实可以写

University( $roster: roster )
$student1: Student() from $roster.get(0)
$student2: Student() from $roster.get(1)

此规则对花名册集合中的前两名学生触发一次,但如果少于两名学生,则必然会引发异常。

University( $roster: roster )
$student1: Student() from $roster
$student2: Student( this != $student1 ) from $roster

每对不同的学生都会触发此规则,一对特定的学生会触发两次规则。