2012-02-25 9 views
1

SubjectTeacherPeriodにはnum_attribute_mapがあります。これは、特定の属性(「退屈さ」など)をそれぞれのスコアでマッピングするマップです。私は次のコードを使用して、各曜日の属性(「退屈さ」など)を合計します。オブジェクトの地図の合計値でエラーが発生する

ただし、一部の行でエラーが発生します。

rule "insertAttributeDayTotal" 
     //salience 1 // Do these rules first (optional, for performance) 
    when 
    $sum_regression_constraint : SumRegressionConstraint(
        $class : class_, 
        $attribute : attribute//, 
        //$weight : weight; 
        ) 
    $day_of_week : DayOfWeek() 
    $attribute_day_total : Number() from accumulate(
     SubjectTeacherPeriod(
      //period != null, 
       period.class_ == $class, 
      period.dayOfWeek == $day_of_week, 
       $total : num_attribute_map[$attribute] //PROBLEM LINE 
      ), 
      sum($total) 
     ) 

    then 
    //System.out.println("BUCKET TOTAL "+$id+" "+$bucket_total.intValue()); 
     insertLogical(new AttributeDaySum($class, $attribute, $day_of_week, $attribute_day_total.intValue())); 
end 

エラーは、次のとおりです。私は、実行時に属性を定義することができるように

[email protected]:~/dev/drools/timetabler$ java -server in.co.technovia.timetabler.TimeTableApp 
Exception in thread "main" java.lang.IllegalStateException: There are errors in the scoreDrl's: 
Variables can not be used inside bindings. Variable [$attribute] is being used in binding 'num_attribute_map[$attribute]' : [Rule name='insertAttributeDayTotal'] 

Rule Compilation error : [Rule name='insertAttributeDayTotal'] 
    in/co/technovia/timetabler/domain/Rule_insertAttributeDayTotal_bb39fd28b3c8457cb8d86fc15b34a0e7.java (7:905) : Syntax error on token "null", invalid Type 
    in/co/technovia/timetabler/domain/Rule_insertAttributeDayTotal_bb39fd28b3c8457cb8d86fc15b34a0e7.java (9:1050) : $total cannot be resolved 

SubjectTeacherPeriodは好奇心num_attribute_mapを持っています。 SubjectTeacherPeriodboringness(int)属性が必要な場合は、SubjectTeacherPeriodに新しい属性を追加する代わりにnum_attribute_map.put("boringness",1)を実行できます。

SumRegressionConstraint特に関心のあるものは、$attributeです。その属性の値はnum_attribute_mapSubjectTeacherPeriodに格納されます。 num_attribute_map[$attribute]にアクセスしますが、この問題が発生します。

私は間違っていますか?


動的属性を使用する他の方法はありますか?

答えて

1

現時点では、フィールド名にのみ変数を式にバインドすることはできません。だからではなく、それを結合させる:にバインドし

$total : num_attribute_map[$attribute] 

:次に

$total : num_attribute_map 

、あなたは機能上の式を使用することができます。あなたはMVELダイアレクトを使用している場合:

sum($total[$attribute]) 

それとも、Javaの方言を使用している場合:

sum($total.get($attribute)) 
+0

を明確にしてください:それは明確な**から 'num_attribute_map [$属性を]'合計んが ' SubjectTeacherPeriod'オブジェクト? – aitchnyu

+0

はい、動作は同じです。関数は各SubjectTeacherPeriodに対して実行され、その中に任意の式を書くことができます。例:sum($ x [$ y] + 2 * $ foo.bar)。通常、人々はsum($ x)のような単純な式を使用します。 –

関連する問題