Creating rules in Oracle Policy Automation

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.

image

Give the project a name and select the language and folder to store the project in.  I called mine “RedStack.”

image

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.

image

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.

image

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.

image

We are going to use the following:

  • Conclusion – this tells OPA that the highlighted text is a conclusion or decision.
  • Level 1, 2, 3, etc. – this tells OPA that the highlighted text is a rule.  Level 1 rules contribute directly to the conclusion.  Level 2 rules contribute to a Level 1 rule, and so on – this will be more clear when we look at our example.
  • Rule Name – this tells OPA that the highlighted text is the name of the rulebase.
  • image Smiley face – This tells OPA to compile the rules to check that they are correct.
  • image Running man – This tells OPA to hide the clause information.

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.

image

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.

image

Next, select the second line and mark it as a Conclusion.

image

Continue in this fashion marking all of the remaining lines as Level 1, except for the two that start with i. and ii.

image

Finally, mark the two remaining lines as Level 2.

image

Your document should now resemble the one shown above.  Now, save your document and then click on the image 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.

image

You will get another dialog box letting you know that the compilation is complete.  Again, click on OK.

image

Your document should now look like this:

image

Note that OPA has added the clause numbers in red.  You can click on image Running man to hide these.  After doing so, your document will look like this:

image

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.

image

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.

image

In the popup dialog box, select Run with Oracle Web Determinations and click on Run.

image

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.

image

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.

image

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.

image

image

image

image

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.

image

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.

image

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.

image

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.

image

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.

image

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.

image

Repeat this same process to create two more screens:

  • Children containing “the employee has given birth to a natural child” and “the employee has taken legal custody of an adopted child”, and
  • Employment containing the remaining two questions.

Your screen should now look like this:

image

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.

image

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.

image

Give the file a name, as we did before.  I called mine dependencies.  Again, you can call yours whatever you like.

image

Right click in the main editor pain (where the popup menu appears in the image below) and select New Item… from the popup menu.

image

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.

image

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.

image

In the dialog box that appears, just click on OK.

image

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.

image

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!

About Mark Nelson

Mark Nelson is an Architect ("IC6") in the Platform Architecture Team in Oracle Development. Mark's focus area is continuous delivery, configuration management and provisioning - making it simple to manage the configuration of complex environments and applications built with Oracle Database, Fusion Middleware and Fusion Applications, on-premise and in the cloud. Before joining the Platform Architecture team, Mark was a senior member of the A-Team since 2010, and worked in Sales Consulting at Oracle since 2006 and various roles at IBM since 1994.
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s