Reference > Rule Languages > ILOG Rule Language > IRL Keywords > not

Summary

A statement that tests the negation of a rule condition.

Syntax

not condition; 

Description

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.

Example

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.

See Also

collect, exists, fork, in