ruletask

The ruletask keyword declares a rule task.

Purpose

The keyword used to declare a rule task.

Context

At the top level of rulesets

Syntax

ruletask ruleTaskName 
{
   [property propertyName = value;] 
   [algorithm = default|sequential;] 
   [matchedclasses = matchedClasses] 
   [iterator = value;] 
   [ordering = dynamic|sorted|literal;] 
   [firing = allrules|rule;] 
   [firinglimit = integer value;] 
   [agendafilter = agendaFilter] 
   [initialaction {action1 ... actionm}] 
   [finalaction {action1 ... actionn}] 
   [completionflag = value;] [scope = scope]
   [body body]
};  
matchedClasses is given a value in one of two ways:
matchedclasses = {class1, class2, ..., classn}
matchedclasses = value;
agendaFilter is defined in one of two ways:
agendafilter = filter(?instance) {action1 ... actions}
agendafilter = value;
body is defined in one of three ways:
body {ruleName1, ruleName2,..., ruleNamep}
body = select(?rule) {action1 ... actionq}
body = dynamicselect(?rule) {action1 ... actionr}

Description

A rule task is one of the three kinds of tasks available in a ruleflow. A rule task lists the rule or rules that define the rule task.

Note:
  1. The ruleflow syntax is described in Grammar specification.

  2. If a formal comment (/**...*/) precedes the task definition, it is saved so that you can retrieve it later using the API.

A rule task can have the following attributes:

  • property

    Use this attribute to define a user property on the task. The engine does not interpret this property. You can retrieve its value by defining API class and methods.

  • algorithm

    The value that follows this keyword indicates which execution mode is used to execute the rules: the RetePlus mode (the algorithm value is then default, which is its default value) or the sequential mode (the algorithm value is sequential).

  • ordering, firing, firinglimit

    A rule task is designed to execute rules. You can set up some rule execution parameters, such as how the rules are ordered and how many rules are executed.

    The keyword ordering specifies how the rules are sorted.

    You can have rules sorted according to the following values:

    • dynamic: The rule instances are sorted in the agenda according to the traditional rules presented for the agenda.

  • agendafilter

    Use the agendafilter keyword in the rule task definition to filter the rules that are actually executed, according to specified criteria.

  • initialaction, finalaction

    You can define an initial action or a final action, or both, for a rule task. Initial actions are executed before the task body. Final actions are executed after the task body. They are composed of inline IRL code, such as IRL functions. They are similar to an IRL function with the void return type and with no arguments.

  • scope

    A scope defines the rules that can be used in the ruletask, before the optional selection defined in the body is applied. The use of a scope is optional.

  • body

    A rule task consists of a list of rules that compose its body. You can specify the rule list either by passing the rule names explicitly (extension), or by using select or dynamicselect keywords so that the list is computed from the code (comprehension). The given code must return a boolean value.

    The use of a task body is optional, but there must be at least a scope or a body.

Example

Example 1

In this rule task, the body consists of the rules DectectConnect4 and DetectGridFull. The rule ordering is set to literal: the order in which the rules are listed in the body is kept for the execution.

ruletask DetectConnect4
{
   ordering = literal;
   body = { DetectConnect4, DetectGridFull }
};
Example 2

In this rule task, the body is defined by comprehension. To compute the body, the code is executed for each rule in the ruleset. The rules for which the return value is true are part of the rule task body. The others are not part of the body.

The ordering here is set to sorted: the rules are sorted in decreasing order of static priority before being executed.

The firing value is set to rule: only one rule is executed among the rules that compose the body, even if more than one are eligible to be executed.

The initial actions are executed before the task body. If final actions are provided, they are executed after the task body.

ruletask ChooseMovePlayer1
{
   initialaction =
   {
      move = null;
   };

   body = select(?rule)
   {
      String ?task = ?rule.getProperties().getString("task","");
      return ?task.equals("ChooseMovePlayer1");
   }
   ordering = sorted;
   firing = rule;
};