As a follow up to this earlier post, we will now explore how to create a basic rulebase using Oracle Policy Automation. This post was created using Oracle Policy Modeling 10.1.0.27 on Windows 2008 Server R2.
Unlike other rules engines, Oracle Policy Automation allows you to write your rules in (or very, very close to) human language, and that language does not have to be English.
In this post, we will create a simple set of rules to determine employee eligibility for leave, and look at how to test the rulebase, and some simple user interface improvements and analysis.
Here are our rules:
Human Resources Policy 100 – Maternity Leave 100.1. The employee is eligible for maternity leave if a. The employee is female and b. Either i. The employee has given birth to a natural child or ii. The employee has taken legal custody of an adopted child and c. The employee is a full time employee and d. The employee has been employed for at least 12 months continuously
Our first step is to open up Oracle Policy Modeling and create a new project. Select New Project… from the File menu.
Give the project a name and select the language and folder to store the project in. I called mine “RedStack.”
Rules can be stored in Word or Excel documents. We will use Word for this example. Right click on the Rules folder and select Add New Word Document from the popup context menu.
Now right click on the newly added Word document and select Rename from the popup context menu. I renamed mine to Maternity Leave.doc as you see in the image below.
Now double click on the Word document to open it in Word. Word will open up with an empty document. Oracle Policy Automation adds a few extra buttons in the Word ribbon. You can see these by clicking on the Add-Ins tab.
We are going to use the following:
Go ahead and type the rules into Word. Take care to put a TAB after the numbers (100.1., a., b., etc.) as this is what tells OPA that these are numbered clauses.
Now we want to tell OPA what the different parts of the document are. First highlight the first line of the document, and mark it as a Rule Name by pressing Alt+N or clicking on Rule Name in the ribbon. Note that the formatting changes slightly to give us a visual clue as to what various parts of the document are.
Next, select the second line and mark it as a Conclusion.
Continue in this fashion marking all of the remaining lines as Level 1, except for the two that start with i. and ii.
Finally, mark the two remaining lines as Level 2.
Your document should now resemble the one shown above. Now, save your document and then click on the Smiley face to compile it. A dialog box will appear to show you the new attributes that were discovered. You can modify wording and other options here, but for now just click on OK to continue.
You will get another dialog box letting you know that the compilation is complete. Again, click on OK.
Your document should now look like this:
You can now close Word and return to Oracle Policy Modeling and we are ready to test our rules. Select Build and Run… from the Build menu.
If you get a message telling you that you need to recompile, just click on Compile and Continue, and then OK in the next dialog box.
In the popup dialog box, select Run with Oracle Web Determinations and click on Run.
This will start up the Oracle Policy Automation server in the background and open a browser directly to the “Web Determinations” screen which will conduct an interview with a user using our rules. Click on the Is the employee eligible for maternity leave? link to start an interview.
OPA will ask you the first question it needs an answer for. You may want to walk through this interview several times, providing different answers to see what happens.
In this example, we will say the employee is female, has not given birth to a natural child, has taken legal custody of an adopted child, is a full time employee and has been for 12 months.
After completing the interview with these responses, OPA tells us that the employee is eligible for maternity leave. Now click on the Why? link after the result.
This will cause OPA to display all of the information provided and show us how it arrived at the decision it did, with direct reference back to the policy/rules we wrote.
So we can see that our rules work the way expected, but the interview is a bit clunky. Let’s take a look at how we can make it a bit nicer.
One way to do this is to group the questions together into logical groups, and display each group of questions on a separate screen, rather than having one question at a time. This is only one of the ways the OPA provides to make our interview more appealing.
Let’s start by right clicking on the Interviews folder and selecting Add New Screens File from the popup context menu.
The name will be highlighted for you to enter a new name. I called mine Leave, but you can call it whatever you like. If you accidentally press Enter too soon, just right click on it and select Rename from the popup menu.
Now double click on your new Interview to open it in the main editing pane (on the right). Next, right click on the Question Screens folder and select New Question Screen from the popup menu.
Enter Sex in the Screen Title field at the top, then click on the New Attribute Input button to add a question to this screen. Select “the employee is female” from the list of available questions (on the right) and click on the Create button to add it to the screen. Questions that you have added will appear on the left hand side. Then click on OK.
Repeat this same process to create two more screens:
Your screen should now look like this:
Now run the project again (select Build and Run… from the Build menu) and observe that the questions are now grouped and labeled as we defined.
Finally, let’s do a little analysis to round out this exercise. Oracle Policy Automation will perform dependency identification for us and identify unused rules and circular logic. Hopefully we wont have any of those in this simple example!
Let’s create a visualisation of our rulebase. Right click on the Visualizations folder and select Add New Visual Browser File from the popup menu.
Give the file a name, as we did before. I called mine dependencies. Again, you can call yours whatever you like.
Right click in the main editor pain (where the popup menu appears in the image below) and select New Item… from the popup menu.
In the dialog box, choose “the employee is eligible for maternity leave” and click on OK. Note that this is our conclusion from our rulebase.
The conclusion will appear in the editor pane, as shown in the image below, as a blue box. Right click on this box and select Generate Rule Structure… from the popup menu. This will help us to visualise the relationships between the rules in our rulebase.
In the dialog box that appears, just click on OK.
A diagram will appear, similar to the one shown below, that shows the rules and conclusions and how they relate to each other. This lets you see how the rules engine goes about collecting facts to arrive at the conclusion.
Well, that’s it for this time! Hopefully that gives you a feel for the simplicity and power of Oracle Policy Automation. Remember, the rules can be much more complex than this, they can be hundreds of pages of legislation or policy documents. They can also be expressed in Excel tables. In addition to the web based interview we saw, they can also be exposed as a service that can be consumed by other applications or by an integration layer.
Next time we will look at how to deploy this rulebase to the Oracle Policy Automation server and consume it as a web service. See you then!