Runtime rule selection

You can use BAL constructs to set up rule selection at run time for execution, either individually or as part of a package. You can also select rules in IRL directly.

At run time, a list of all the rule packages and rules that you defined for each ruleflow task is generated. Each rule is considered for execution. However, you can define how your rules are selected at run time to refine the list of rules that are considered for execution and filter out some of them. This is called runtime rule selection.

Note:

An empty list of rules and packages means that all the rules from the project are selected for execution at run time.

You can select rules for execution in either of these ways:

Typically, the filtering process is based on the values of rule properties and execution parameters. The filter tests each rule in the ruleflow task to determine whether the rule should be selected for execution. For example, the following code filters on the name of the rule and is called for every rule in the task.

the name of 'the rule' contains "Age"

You can further refine run time rule selection by using specific BAL constructs such as is, is over, is under, to define hierarchical relationships between the rules (see ../../com.ibm.odm.dserver.rules.designer.author/authoring_topics/con_rul_hierarchies.html).

In the classic rule engine, you can set run time rule selection to be either dynamic or static. The selection method changes the way the filter is applied to the rules.

More specifically, you can select rules directly in IRL in the following ways:

Static body

The list of rules is specified simply by including the names inside the rule task body.

body = { R1, R2 }

Static body using the select keyword

Here is an example of selecting rules using the select keyword:

body = select(?rule) { <boolean returning code> }

This first example shows that a body of the rule task can be an IRL predicate that selects the relevant rules among all the rules of the ruleset.

In this second example, the specification selects all the rules available in the ruleset:

body = select(?rule) { return true; }

In the classic rule engine, the rules are selected only once regardless of how many times the rule task is executed.

Note:

In the decision engine, there is no difference between dynamicselect and select. select behaves the same way as dynamicselect where the statement is called each time the task is executed.

Dynamic body

The list of rules is selected by a function-like expression that takes an IlrRule object as its argument and evaluates to a Boolean expression. The pseudo-variable ?rule represents the IlrRule argument of the expression. This filter applies to each rule in the ruleset each time the rule task is activated. Hence, this expression might well depend on environment variables such as ruleset parameters or fields whose values can change between two executions of the rule task.

body = dynamicselect(?rule) {
      return myRuleSelection(?rule);
   }

Dynamic body in a domain

The domain is an expression that evaluates to a Java™ array or collection of IlrRule objects. The dynamic body is also an expression. You can use expressions to select the subset of the rules of the domain for the next rule task execution. The dynamic body is evaluated each time the rule task is activated.

It accepts two different signatures.

Dynamic body that returns a collection of rules

The dynamic body is an expression that evaluates to a Java array or collection of an IlrRule object.

   body = dynamicselect() {
      return myRuleDomainSelection();
   }
   in myInitialRuleDomain();
Attention:

There is no check at run time that the collection of rules returned by the dynamic body is really a subset of the initial rule domain. You must enforce such verification. Otherwise, a crash might occur.

Dynamic body that returns a Boolean value

The dynamic body is a function-like expression that takes an IlrRule object as its argument and evaluates to a Boolean expression. The pseudo-variable ?rule represents the single IlrRule argument of the expression. The engine passes to this rule filter only the rules that belong to the initial rule domain.

   body = dynamicselect(?rule) {
      return myRuleSelection(?rule);
   }
   in myInitialRuleDomain();

See Memory consumption reduction for more information.

Scope

The scope defines in a symbolic way what rules compose the body of a rule task. This provides a simpler way of describing the selection than using IRL expressions such as an in expression. The scope makes use of the package organization.

Note:

Because the IRL in expression and the scope provide alternate selection methods, you cannot use them together.