before

The 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:

  1. ?event 1 before[min,max] ?event 2

    is satisfied if the value of t2 - t1 is between the values of min and max, inclusive.

  2. ?event 1 before[min,$] ?event 2

    is satisfied if the value of t2 - t1 is greater than, or equal to, the value of min.

  3. ?event 1 before[$,max] ?event 2

    is satisfied if the value of t2 - t1 is less than, or equal to, the value of max.

  4. ?event 1 before ?event 2

    is satisfied if the value of t2 - t1 is 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);
   }
};