1

私たちの ILOG ルール IRL ファイルでは、コレクションから変数を設定し、最初のオブジェクトと等しくないコレクションから別の変数を設定することが多数発生しています。

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

ILOG では、これらの行はコレクション内の最初と 2 番目のオブジェクトを返すだけですか?

以下は、drl ルール ファイル内の Drools で同じことを行うための最良の方法でしょうか?

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

1 に答える 1

1

ILOG の動作を確認できるはずなので、Drools の部分に答えているだけです。

Drools では、 を使用して、範囲内のコレクションからオブジェクトを取得できますfrom <expression>。したがって、実際に書くことができます

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

このルールは、名簿コレクションの最初の 2 人の学生に対して 1 回実行されますが、学生が 2 人未満の場合は必ず例外が発生します。

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

このルールは、順序付けられた異なる生徒のペアごとに起動し、1 つの特定のペアが 2 つのルールを起動します。

于 2015-10-08T04:52:23.657 に答える