Open Your Business Rules!
Rules-based
Operational Decision Services
OpenRules Classic: Examples
Here are several examples that can help you quickly understand how OpenRules® represents decisions and supporting decision tables. Follow the links below to see different spreadsheets with business rules:
-
DecisionHello.xls - decision that defines customer greetings based on the time of day and customer's attributes
-
DecisionUpSell.xls - simple customer profiling and up-selling rules
-
Decision.xls, Rules.xls, Glossary.xls, Data.xls - loan pre-qualification decision
-
DecisionVacationDays.xls - decision that calculates vacations days.
What you will see are actually working decision models created in Excel without programming. Using the familiar Excel interface, a business analyst can enter decisions along with supporting decision tables and test cases, and then execute the decision to verify that it produces the expected results.
A detailed description of these and other decision projects are provided in the document "Getting Started". You may also watch brief videos with simple explanations.
Decision "Hello Customer"
Below we will explain the first decision presented in the file DecisionHello.xls. It decides how to greet a customer during different times of the day. For example, if a customer, Robinson, is a married woman and the local time is 20:25, we want our decision to produce the following greeting: "Good Evening, Mrs. Robinson!"
In order to make this decision we need to make two sub-decisions:
- Define Greeting Word (e.g. “Good Afternoon”)
- Define Salutation Word (e.g. “Mrs.”)
OpenRules® provides special tables for representing decisions where each sub-decision is implemented as a Decision Table. So, first we will create an Excel table “DetermineCustomerGreeting” of the type "Decision":
Decision DetermineCustomerGreeting | |||
Decisions | Execute Rules | ||
Define Greeting Word | := DefineGreeting() | ||
Define Salutation Word | := DefineSalutation() | ||
Print Greeting | := System.out.println(response.greeting + ", " + response.salutation + customers[0].name + "!") |
The first column of this table defines the decision name and the second column defines the decision table that implements the related (sub) decision. The first decision table determines a greeting word based on the current hour:
DecisionTable DefineGreeting |
|
If |
Then |
Current Hour |
Greeting |
0-11 |
Good Morning |
11-17 |
Good Afternoon |
17-22 |
Good Evening |
22-24 |
Good Night |
The second decision table determines a salutation word based on the customer gender and marital status:
DecisionTable DefineSalutation |
|||||
Condition |
Condition |
Conclusion |
|||
Gender |
Marital Status |
Salutation |
|||
Is |
Male |
|
|
Is |
Mr. |
Is |
Female |
Is |
Married |
Is |
Mrs. |
Is |
Female |
Is |
Single |
Is |
Ms. |
These decision tables deal with decision variables that are described in the following glossary:
Glossary glossary |
||
Decision Variable |
Business Concept |
Attribute |
Gender |
Customer |
gender |
Marital Status |
maritalStatus |
|
Greeting |
Response |
greeting |
Salutation |
salutation |
|
Current Hour |
hour |
We associate all facts with the proper business concepts like Customer and Response and their attributes. The proper concepts can be defined as Java objects, Excel tables, or XML files. Here is the their representation in Excel tables:
Datatype Customer |
|
String |
name |
String |
maritalStatus |
String |
gender |
int |
age |
Datatype Response |
|
String |
greeting |
String |
salutation |
int |
hour |
We may also create test cases for these data types directly in Excel:
Data Customer customers |
|||
name |
maritalStatus |
gender |
age |
Customer Name |
Marital Status |
Gender |
Age |
Robinson |
Married |
Female |
24 |
Smith |
Single |
Male |
19 |
Variable Response response |
||
greeting |
salutation |
hour |
Greeting |
Salutation |
Current Hour |
? |
? |
20 |
We may execute this decision from a standard Java program (that is provided and contains just two lines) and it will produce the following results:
Define Current Time
Conclusion: Current Hour is 20
Define Greeting Word
Conclusion: Greeting is Good Evening
Define Salutation Word
Conclusion: Salutation is Mrs.
Print Greeting
Good Evening, Mrs. Robinson!
The same decision can work with Java objects or it can be deployed as a web service.
You may evaluate many other examples doing OpenRules® evaluation. The evaluation version includes many decision models and does not require any installation. You may take a look at the decision project Excel and Java files, and analyze the results of their execution. Many of these projects are described in detail in the Getting Started document and other Tutorials.
Click here to look at many more decision models in Excel along with their execution results.
The complete OpenRules installation also includes:
To learn more, please download these and other examples from here, change the rules, and run them from the provided batch-files or from your own Java code. See how complex projects with extensive rules and web components can be organized and maintained under Eclipse plug-ins.