overriding, overrides

The overriding and overrides keywords declare overriding relations.

Purpose

The overriding and overrides keywords are used to declare overriding relations.

Context

At the top level of rulesets

Syntax

overriding { "groupName1" overrides "groupeName2"; 
   "groupName3" overrides "groupName4", "groupName5"; } 

Description

You can organize rules in groups by using an ilog.rules.group rule property. The overriding keyword introduces overriding declarations which apply to the rules that compose a rule task and take groups as parameters. In the parameter block, the overrides keyword indicates which rule group is executed instead of which other rule groups: a declaration in which group1 overrides group2 means that when rules of group1 are together with rules of group2 in a rule task, the rules of group2 are removed from the task and therefore not executed. Rule overriding is the last rule selection done before the task is executed.

If a rule does not define an ilog.rules.group property, a default one is created. Its value is the fully qualified name of the rule.

Example

import java.util.Collection;

hierarchy Geography
{
  "North" {
   "USA" {
      "California"
      ...
   }
   ...
  }
}

propertydefinition
{
   Geography location;
}

overriding
{
  "california" overrides "usa";
  "blocklisted" overrides "california";
}

rule usa
{
  property location = "USA";
  when {
   ...
  }
  then {
   ...
  }
}
rule california
{
  property location = "California";
  when {
   ...
  }
  then {
   ...
  }
}
rule blocklisted
{
  property ilog.rules.group = "blocklisted";
  when {
   ...
  }
  then {
   ...
  }
}

ruletask main
{
  body = dynamicselect(){
    Collection rules = collect IlrRule(?this.?location match up "California") 
in getRuleset().getAllRules();    
    return rules;
  }
}

This example defines a rule task that selects all the rules in which the location property matches up the value California. The resulting selection contains the rules in which the value of the location property is one of the values in the Geography hierarchy from the root (North) to the California node.

The collected rules are usa and california. These rules have not defined an ilog.rules.group property. Therefore, the property value for these rules is their fully qualified names, here usa and california. The overriding declaration removes the usa rule from the selection and keeps only the california rule.