| Reference > Rule Languages > ILOG Rule Language > IRL Keywords > not |
not |
PREVIOUS NEXT |
A statement that tests the negation of a rule condition.
not condition;
The not statement is used in the condition part of a rule. It may be applied to a simple condition, an in statement, or a from statement. The not statement returns true if the specified condition is false. A not condition returns true for a simple condition if the working memory does not contain any object that can match the condition. A not statement returns true with an in or from statement when the in or from statement returns false. Use not for the contrary of both exists class or just class.
A not condition cannot be bound to an external variable. The not condition returns true when no object in the working memory matches the condition. Hence it is illegal to bind a false condition to a variable.
Any variable bound within the not condition is local to the condition. It cannot be referred to in the remainder of the rule.
The special variable ?this may be used within the not statement to designate the current working memory object being tested.
rule GuestPromotion {
when {
?g:Guest(?i:id);
not GroupId(this.contains(?i));
}
then {
?g.promotions();
}
}
The GuestPromotion rule verifies that a guest is not part of a group, in order to provide a promotion. The first condition uses the variable ?g to reference a Guest object and the variable ?i to return the field value id. The not statement is used to test if this id is contained in the object GroupId using the method contains applied to the variable ?this. The then part launches the method promotions().
rule LargestPercentStockChange {
when {
?s: Stock(?c:currentValue; ?l:lastClosing; ?p:(?c-?l)/?l);
not Stock(?c1:currentValue; ?l1:lastClosing; ?p < (?c1-?l1)/?l1);
}
then {
System.out.println(?s.ticker + "has the largest change of: "+ ?p +"%");
}
};
The purpose of the LargestPercentStockChange rule is to print out the stock with the largest percent change.
?s, specifies a stock, and the rule variables named ?c and ?l are bound to the current stock value and the last closing value, respectively. The stock percent change is calculated and saved as ?p.
not keyword. Similar to the previous condition, we calculate a percent change with rule variables ?c1 and ?l1. The condition then compares the result with the previous calculated change ?p. The not keyword will cause the condition to fail for any percentage change except the largest.
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |