X

Best Practices from Oracle Development's A‑Team

Creating rules in Oracle Policy Automation

Mark Nelson
Architect

Introduction

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.

Main Article

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.”

image1

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.

image2

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.

image3

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.

image4

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.
  • image5 Smiley face – This tells OPA to compile the rules to check that they are correct.
  • image6 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.

image7

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.

image8

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

image9

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

image10

Finally, mark the two remaining lines as Level 2.

image11

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

image12

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

image13

Your document should now look like this:

image14

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

image15

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.

image16

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.

image17

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

image18

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.

image19

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.

image20

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.

image21 image22 image23 image24

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.

image25

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.

image26

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.

image27

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.

image28

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.

image29

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.

image30

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:

image31

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.

image32

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.

image33

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

image34

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

image35

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.

image36

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.

image37

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

image38

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.

image39

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!

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha