after

The after keyword defines a binary temporal constraint in the condition part of a rule in an event condition.

Purpose

A binary temporal constraint in an event condition.

Context

Rule conditions

Syntax

[?var:] event className (?eventVar1 after [interval] ?eventVar2);

Description

Deprecated as of V7.5.

The after keyword is used in the condition part of a rule in an event condition. You express a temporal constraint between two events with 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 t 1 and that the timestamp of ?event 2 is t 2, you can express the after operator as follows:

  • ?event 2 after[min,max] ?event 1

    is satisfied if the value of t 2 - t 1 is between the values of min and max, inclusive.

  • ?event 2 after[min,$] ?event 1

    is satisfied if the value of t 2 - t 1 is greater than, or equal to, the value of min.

  • ?event 2 after[$,max] ?event 1

    is satisfied if the value of t 2 - t 1 is less than, or equal to, the value of max.

  • ?event 2 after ?event 1

    is satisfied if the value of t 2 - t 1 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 a second alarm event ?a2 is inserted no later than four ticks after ?a1.

rule ReportAlarmPairsToUsers {
   when {
      ?u: User();
      ?a1: event Alarm();
      ?a2: event Alarm(?this after[1, 4] ?a1);
   } 
   then {
      ?u.report(?a1, ?a2);
   }
};