我使用Drools(第一次)來表達一些規則,並且它一直在工作迄今爲止。不過,我得到了一個新的條件,我無法用規則語言很清楚地表達出來。編寫Drools/JBoss規則的LHS時出現問題,我匹配一個事實,然後使用該事實來確定是否存在其他事實
基本上我需要對玩家賬戶執行一個操作,如果他們在賬戶之間有一定的餘額,在一定的金額之間,他們還沒有在上週進行支付,他們還沒有進行支付在過去4周內,大於或等於每週扣除。還有其他一些規則,但爲了簡化此問題的規則,我已將其刪除。這是導致我出問題的最後一條規則。
rule "The broken rule"
salience 10
no-loop
when
Player($playerNumber : playerNumber)
$a : Account(// balance between £5 and £100 and no arrangement
playerNumber == $playerNumber &&
accountBalanceInPence >= 500 &&
accountBalanceInPence <= 10000
)
not (// no payment in last week
exists AccountTransaction(
playerNumber == $playerNumber &&
transactionDate >= oneWeekAgo &&
transactionCode == "P" // payment
)
)
/* It's this next bit that is broken */
not (// no payment > (weekly cost * 4) paid within last 4 weeks
$deduction : AccountTransaction(// a recent transaction
playerNumber == $playerNumber &&
transactionDate >= fourWeeksAgo &&
transactionCode == "D" // deduction
)
exists AccountTransaction(// the payment
playerNumber == $playerNumber &&
transactionDate >= fourWeeksAgo &&
transactionCode == "P" // payment
amountInPence >= ($deduction->amountInPence * 4)
)
)
then
// do some action to the account
end
問題是它只是不起作用,我不斷得到org.drools.rule.InvalidRulePackage異常拋出。我只是在猜測語法,但似乎無法找到一個示例顯示我正在嘗試做什麼。它甚至有可能嗎?
完整的原始的錯誤消息是:
"unknown:50:3 mismatched token: [@255,1690:1695='exists',<39>,50:3]; expecting type RIGHT_PAREN[54,4]: unknown:54:4 mismatched token: [@284,1840:1852='amountInPence',<7>,54:4]; expecting type RIGHT_PAREN[54,22]: unknown:54:22 Unexpected token '$payment'"
在第一個註釋嘗試建議錯誤後是:
"[50,3]: unknown:50:3 mismatched token: [@255,1690:1695='exists',<39>,50:3]; expecting type RIGHT_PAREN[54,4]: unknown:54:4 mismatched token: [@284,1840:1852='amountInPence',<7>,54:4]; expecting type RIGHT_PAREN[54,45]: unknown:54:45 mismatched token: [@293,1881:1881='*',<71>,54:45]; expecting type LEFT_PAREN[55,3]: unknown:55:3 mismatched token: [@298,1890:1890=')',<12>,55:3]; expecting type THEN"
不幸的是,沒有工作,我會更新與錯誤消息更詳細的問題(他們不不適合發表評論)。 – BenM 2009-01-06 10:59:05
我認爲這是一個編輯錯字 - 是的,「 - >」似乎是錯誤的。這是一個不再需要的舊語法。 – 2009-01-07 02:51:46