Samples > Rule-Based Programming > How to Use Pattern Matching to Apply Rules on a Set of Objects

This sample shows how to use different pattern-matching techniques and uses the RetePlus algorithm to automate processing of a set of objects.

Key Features

Key features include:

Importing this Sample

To import the patternmatching sample:

  1. Click File > Import.
  2. In the Import Wizard, select ILOG Rule Studio Samples and Tutorials and click Next.
  3. Select the samples > engine > patternmatching sample.
  4. Click Finish.
  5. If one or more files already exist in your workspace, a warning message is displayed indicating that the corresponding file(s) were not re-imported. Close the message window.

The imported sample project files are displayed in the Rule Explorer.

Running this Sample

Make sure you are in the Rule perspective before running this sample.

To run the patternmatching-rules Rule Project:

  1. Click Run > Open Run Dialog.
  2. Select the Rule Project > patternmatching-rules launch configuration.
  3. Click Run.

Output is displayed in the Console view.

To run the patternmatching-application Java Application:

  1. Click Run > Open Run Dialog.
  2. Select the Java Application with Rules > patternmatching-application launch configuration.
  3. Click Run.

Output is displayed in the Console view.

Highlights

This sample includes two projects:

The Business Object Model

Rules are applied on a set of objects of several classes. This object model, also called Business Object Model (BOM), is mapped onto an equivalent Java Execution Object Model (XOM), and is a simple object model made of a few interfaces, implementation classes, and factories. This object model is referenced from the financialevent-xom Java project.

Pattern Matching

The rule conditions match various object patterns (listed above in the Key Features list). The rules then use the matched objects in their actions, which are written in Java syntax.

Incremental Behavior of the Engine

As the engine uses a RetePlus algorithm, and this algorithm works natively in an incremental and stateful manner, all important changes on the objects (through the insert, update, and retract keywords) are taken into account by the engine, which then re-evaluates which rules to execute accordingly.

Rule Ordering

The engine determines the order of execution based on the priority property of the rules and the recency of the object changes. The default refraction mechanism avoids executing the same rule several times on the same object instances, even if the rule conditions are met again after a change on an object.

Related Concepts

Technical Rules
RetePlus

Related Tasks

Working with Technical Rules

Related Reference

BOM and XOM
when
collect
not
priority

Related Samples and Tutorials

Import Samples and Tutorials Wizard