私はDrools規則を書くのに助けが必要です。私はContextとCreditReportの2つのクラスを持っています。Drools:文字列からオブジェクトへのマップを含む規則
コンテキストは、ルールが起動される前にファクトとしてナレッジセッションに挿入されます。
は、私は直接セッションにCreditReportを挿入したい、版画「エクセレント」コンソールには、クレジットスコアが800以上
理想的であるルールを記述する必要があるが、残念ながら私はそれを持っていません。オプション。
私のように良い見ていない書いたルール:
- が、その後部分がありif文私は
ご協力いただきありがとうございます。
// Context.java
public class Context {
private Map<String, Object> data = Maps.newHashMap();
public <T> T getData(final String key, final Class<T> clazz) {
return clazz.cast(data.get(key));
}
public void putData(final String key, final Object value) {
this.data.put(key, value);
}
}
// CreditReport.java
public class CreditReport {
private final String name;
private final int creditScore;
public String getName() {
return this.name;
}
public int getCreditScore() {
return this.creditScore;
}
}
// Mainメソッド
context.put("creditReport", new CreditReport("John", 810));
session.insert(Arrays.asList(context));
session.fireAllRules();
//ルール
rule "Excellent_Score"
when Context($creditReportObject : getData("creditReport"))
then
final CreditReport creditReport = (CreditReport) $creditReportObject;
if (creditReport.getCreditScore() >= 800) {
System.out.println("Excellent");
}
end
ありがとうございます!あなたはすべての点数が正しいです。 1つのフォローアップの質問。 ContextにAccountという別のオブジェクトが含まれている場合CreditReport.creditScore> = 800またはAccount.balance> = 5000のときに、「Excellent」と表示されるルールを作成したいと思いますか? OR関係ではなくOR関係でルールを書く方法は分かっています。私もevalの使用を避けようとしています – user544192
単一のルールではあまり得られません。 – laune
もう一度ありがとう! :) – user544192