| Samples > Rule-Based Programming > How to Use Pattern Matching to Apply Rules on a Set of Objects |
How to Use Pattern Matching to Apply Rules on a Set of Objects |
PREVIOUS NEXT |
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 include:
To import the patternmatching sample:
samples > engine > patternmatching sample.
The imported sample project files are displayed in the Rule Explorer.
Make sure you are in the Rule perspective before running this sample.
To run the patternmatching-rules Rule Project:
Rule Project > patternmatching-rules launch configuration.
Output is displayed in the Console view.
To run the patternmatching-application Java Application:
Java Application with Rules > patternmatching-application launch configuration.
Output is displayed in the Console view.
This sample includes two projects:
patternmatching-rules contains a ruleset consisting of several simple financial events (such as withdrawal, debit, transfer). An ilrmain function creates and inserts objects into working memory and executes the ruleset. Output is displayed in the Console view.
patternmatching-application runs the ruleset from a Java application. A main method loads objects from a data source (Accounts.xls), inserts them into working memory, sets the ruleset parameters, and executes the rules.
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.
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.
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.
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.
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |