ルール変数へのルール・アクションの依存
ルールがその変数をインスタンス化できない場合、ルールのアクションを実行することはできません。
ルール変数は、ルールの definitions 部分と when 部分に定義します。ルールはその変数をインスタンス化できない場合、つまり変数が既存のデータに一致しない場合、アクションを実行することはできません。
ルールに変数と条件がある場合は、変数をインスタンス化でき、条件が true でない場合にのみ、ルールはその else 部分を適用することができます。
次のルールでは、すべての顧客が最低でも 5% の割引を受けるため、必ず割引が適用されます。
if
all of the following conditions are true:
- the value of the shopping cart of 'the customer' is more than 100
- the category of 'the customer' is Gold
then
print "apply a 15% discount";
else
print "apply a 5% discount";
ただし、definitions 部分を使用してルールを変更し、ゴールド・カテゴリーの顧客のみに割引を提供するようにできます。
when a purchase event occurs
definitions
set 'the customer' to the customer of this purchase event
where the category of this customer is Gold;
if
the value of the shopping cart of 'the customer' is more than 100
then
print "apply a 15% discount";
else
print "apply a 5% discount";
また、200 を超える金額を購入した顧客のみに割引を提供するように、when 節を使用してルールを変更することもできます。
when a purchase event occurs
where the amount of this purchase event is more than 200
if the category of 'the customer' is Gold
then
print "apply a 15% discount";
else
print "apply a 5% discount";