| The OpenRulesTM Tutorials Home |
|
Decision tables |
Using Natural Language Expressions Inside OpenRules Tables
This document will explain how rules could be expressed in plain English in OpenRules decision tables. The concrete examples will be shown to demonstrate the use of natural language expressions to define different rules. We will take a relatively complex decision table and will show how to use predefined OpenRules types such as FromToInt, CompareInt, and DomainString to simplify this table for a business user. While simplicity is always a matter of taste, the actual objective is to demonstrate the use of natural language inside OpenRules tables.
Comparing Integer and Real Numbers
Representing Domains of Numbers
We will use a decision table "DebtResearchRules" from the sample rule project "Loan1" included into the standard OpenRules installation. Here is the default representation of the debt research rules:
| Rules void DebtResearchRules(LoanRequest loan, Customer c) | ||||||||||||||
| C1 | C2 | C3 | C4 | C5 | C6 | C7 | A1 | |||||||
| c.mortgageHolder.equals(YN) |
c.outsideCreditScore>min && c.outsideCreditScore<=max |
c.loanHolder.equals(YN) | op.compare(c.creditCardBalance,value) | op.compare(c.educationLoanBalance,value) | contains(rates,c.internalCreditRating) | c.internalAnalystOpinion.equals(level) |
loan.debtResearchResult = level; out("Debt Research Result:"+level); |
|||||||
| String YN | int min | int max | String YN | Operator op | int value | Operator op | int value | String[] rates | String level | String level | ||||
|
IF Mortgage Holder |
AND Outside Credit Score |
AND Loan Holder |
AND Credit Card Balance |
AND Education Loan Balance |
AND Internal Credit Rating |
AND Internal Analyst Opinion |
THEN Debt Research Recommendations |
|||||||
| Min | Max | Oper | Value | Oper | Value | |||||||||
| Yes | High | |||||||||||||
| No | 100 | 550 | High | |||||||||||
| No | 550 | 900 | Yes | <= | 0 | Mid | ||||||||
| No | 550 | 900 | Yes | > | 0 | > | 0 | High | ||||||
| No | 550 | 900 | Yes | > | 0 | <= | 0 | A | B | C | High | |||
| No | 550 | 900 | Yes | > | 0 | <= | 0 | D | F | Mid | ||||
| No | 550 | 900 | No | > | 0 | Low | ||||||||
| No | 550 | 900 | No | <= | 0 | <= | 0 | Low | ||||||
| No | 550 | 900 | No | <= | 0 | > | 0 | D | F | High | ||||
| No | 550 | 900 | No | <= | 0 | > | 0 | A | B | C | Low | |||
| High | High | |||||||||||||
| Mid | Mid | |||||||||||||
| Low | Low | |||||||||||||
We are going to modify conditions C2, C4, C5, and C6 by using different OpenRules representation options.
The condition C2 above represents the fact that customers's outside credit score should be between min and max. To be exact, the condition is presented as the following Java snippet:
c.outsideCreditScore>min && c.outsideCreditScore<=max
where min and max are parameters defined in two different sub-columns of the column C2. Note that the comparison logic is hard-coded inside implementation: c.outsideCreditScore is strictly greater than min and less than or equals to max. We may easily switch to only one column and allow a business user him/herself to define the comparison logic for each particular rule using any reasonable representation of an interval min-max. Here is an example of the properly modified condition C2:
| C2 |
| interval.contains(c.outsideCreditScore) |
| FromToInt interval |
|
AND Outside Credit Score |