| Samples > Rule-Based Programming > How to Select Rules to be Executed |
How to Select Rules to be Executed |
PREVIOUS NEXT |
This sample shows how to use strategies to select which rules are evaluated for a given task. Please note the information provided in Using the Samples.
This sample shows how to use various strategies for selecting which rules should be evaluated for a given task. This is particularly useful when rules become numerous and specialized.
In JRules, rule selection relies on a selection pipeline that behaves like a series of filters, using rule properties instead of rule conditions.
As this sample will install a custom rule model instead of the default one, it is recommended to explore and run it in a separate workspace.
To prepare a new workspace:
To import the ruleselection sample:
samples > engine > ruleselection.
ILOG Rule Studio > RuleModelExtension, set the Extension model to ruleselection-rules/data/ruleselection.brmx, and set the Extension data to ruleselection-rules/data/ruleselection.brdx.
The rule model extension and its attached data file are now recognized by Rule Studio.
Make sure you are in the Rule perspective before running this sample.
To run the sample:
ruleselection-rules-case1 launch configuration.
ruleselection-rules-case2 and the ruleselection-rules-case3 launch configurations.
The console trace shows that, given a different extractor and a different input parameter, different rules are extracted, selected and fired.
The selection strategy is split into two phases:
This sample loads the ruleselection-rules rule project and the ruleselection-xom XOM project. Rules evaluate a contract status based on information about the company featured in the contract, and information about the contract itself.
A first ruletask, called assessment, evaluates a risk level based on the company revenue, a rating of the company, and the amount of the contract.
A second ruletask, called decision, determines the status of the contract (using a set of predefined status values such as ACCEPTED, REFUSED, NEGOCIATE), based on the evaluated risk level and the expected profit from the contract.
The rule model extension located in the data directory of the ruleselection-rules project, enhances the rules in the sample with the following properties:
targetRelease, a 'struct' property defined by a major and a minor version, a patch level, a production level (`Test', 'Beta', 'Production') and a desired deployment date for the rule.
origin, another 'struct' property containing the requestor and the requirement ID that lead to this rule.
industry, a hierarchical property that models the industries to which a rule is applicable, using a predefined breakdown of industry types.
location, a hierarchical property that models the effective location of the rule within a geographical breakdown of the world.
customers, a textual property that identifies, if needed, the companies that this rule is valid for.
Using the default behavior of the product and these properties, rule selection implements the following strategy:
status, targetRelease and effective location of the rule. The generated archive contains only the rules considered as valid for a given application release and a given region of the world. For example, the extractor V1-production-Americas uses the query with the same name, returns only rules for the V1.2 production release, valid worldwide and in the American continent. The other extractor, V2-beta-Europe uses the query with the same name, defined for V2.0 beta version, valid worldwide and in Europe.
assessment package and its sub packages go in the assessment ruletask; rules in the decision package go in the decision ruletask. This is enforced when the ruleset archive is loaded by the rule engine.
With the ruleselection-rules-case1 launch configuration, which evaluates a contract with a software company in north California with the V1 production application, only the following rules are retained:
assessment.amount.V1-NorthAmerica-Software
assessment.rating.V1-NorthernCalifornia-Software
assessment.revenue.V1-NorthAmerica-Software-SmallCompany
assessment.revenue.V1-NorthAmerica-Software-MediumCompany
assessment.revenue.V1-NorthAmerica-Software-LargeCompany
V1-decision
And only the following rules are fired:
assessment.revenue.V1-NorthAmerica-Software-LargeCompany
assessment.rating.V1-NorthernCalifornia-Software
assessment.amount.V1-NorthAmerica-Software row #4
decision.V1-decision_4 row #4
V2-* and *-Europe-* rules are not extracted by the query.
Rules such as assessment.rating.V1-NorthAmerica-Services and assessment.rating.V1-BlackList-NorthernCalifornia-Software are in the ruletask scope, but are rejected by the dynamicselect.
Finally, assessment.rating.V1-NorthAmerica-Software is overridden by assessment.rating.V1-USA-Software, which is overridden by assessment.rating.V1-NorthernCalifornia-Software.
With the ruleselection-rules-case2 launch configuration, which evaluates a contract with a French Bank agency in Italy with the V2 beta application, only the following rules are retained:
assessment.amount.V2-Europe-Services
assessment.rating.V2-Europe-Services
assessment.revenue.V2-Europe-Services-AllCompanies
decision.V2-decision
And only the following rules are fired:
assessment.revenue.V2-Europe-Services-AllCompanies
assessment.rating.V2-Europe-Services row #2
assessment.amount.V2-Europe-Services row #5
decision.V2-decision row #4
V1-* and American rules are not extracted by the query.
The ruleselection-rules-case3 launch configuration evaluates a contract with a Software company named Swindle Systems in Northern California with the V1 production application. In this case, the rule assessment.rating.V1-BlackList-NorthernCalifornia-Software is selected during the dynamic selection, and overrides the assessment.rating.V1-NorthernCalifornia-Software rule and all rules that were overridden by the latter.
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |