before
before keyword defines a binary temporal
constraint.
Purpose
This keyword is used to define a
binary temporal constraint in an event condition.
Context
Rule conditions
Syntax
[?var:] event className(?eventVar1 before [interval] ?eventVar2);
Description
Deprecated as of V7.5.
Use
the before keyword in the condition part of a rule
in an event condition. To express a temporal constraint between two
events, you use the after and before keywords.
An interval is of the form [lowerBound, upperBound],
where a bound is either an expression evaluating to an integer, or
the $ sign which denotes infinity.
Considering that the timestamp
of ?event 1 is t1 and
that the timestamp of ?event 2 is t2,
you can express the before operator as follows:
?event1before[min,max] ?event2is satisfied if the value of
t2 - t1is between the values ofminandmax, inclusive.?event1before[min,$] ?event2is satisfied if the value of
t2 - t1is greater than, or equal to, the value ofmin.?event1before[$,max] ?event2is satisfied if the value of
t2 - t1is less than, or equal to, the value ofmax.?event1before ?event2is satisfied if the value of
t2 - t1is positive or null.
Example
This example assumes that a User instance
is in the working memory and that an Alarm instance
is inserted. A partial instance of the ReportAlarmPairsToUsers rule
is created and maintained for four ticks. If the User instance
is then retracted, the partial instance of the rule is immediately
deleted. An instance of the ReportAlarmsToUsers rule
is created on each instance of the User class in
the working memory when ?a1 is no greater than 4
ticks before a second alarm event ?a2 is
inserted.
rule ReportAlarmPairsToUsers {
when {
?u: User();
?a1: event Alarm();
?a2: event Alarm(?a1 before[1, 4] ?this);
} then {
?u.report(?a1, ?a2);
}
};