Use an entity or relationship in a rule

To write rules in Oracle Policy Modeling you need to understand how to refer to the different parts of the data model within your rules.

What do you want to do?

Refer to entities connected by a to-many relationship

Refer to entities connected by a to-one relationship

Compare entities within the same relationship

Count the number of instances of an entity

Get the highest/most recent value of an entity-level variable

Get the lowest/least recent value of an entity-level variable

Add up numerical values gathered from each instance of an entity

Refer to entities connected by a to-many relationship

Anytime you refer from one entity to another entity in a "to-many" relationship, you need to indicate whether one or all members of the target entity group need to satisfy the rule.

Consider the following rule:

A family may board the plane first if their child is under 8 years of age

 

We know that families can have more than one child, however, this rule does not specify whether one or all of the family's children must be under 8 years of age in order for the family to board the plane first. If the family had 2 children, one aged 4 and one aged 16, how would you decide?

The rule would be clearer if written in such a way that the reader can tell whether the rule applies to one or all children. For example:

A family may board the plane first if they have at least one child under 8 years of age

 

We use quantifiers, which are a type of Oracle Policy Modeling syntax, to write these kinds of rules. Quantifiers are operators which access data across the instances of an entity. The two quantifiers we use are:

Check that a condition returns true for every instance of an entity

The universal quantifier must be used when you refer from one entity to another entity in a "to-many" relationship, AND you need to determine whether all members of the target entity group need to satisfy the rule. This quantifier works in much the same way across entities as the 'and' operator does across attributes. This means that the condition using the universal quantifier will only evaluate to true when the condition is true for all instances of an entity.

 

There are two types of entity function that are used as universal quantifiers:

1. For All - this function is used where there is only one condition. For example, you could have the following rule where 'the family' is an entity (the source entity), 'the child' is an entity (the target entity), and 'the children' is the relationship between the entities (the relationship text).

 

the family is ready to travel overseas if

ForAll(the children, the child has a passport)

 

2. For All Scope - this function is used where there are one or more conditions (eg when you want to reason across several different relationships in the one rule). For example, you could have the following rule where a customer entity has a one-to-one relationship to a plan entity (the customer's current plan) which has an inferred many-to-many relationship to specific products (the plan's products).

 

the customer is satisfied if

in the case of the customer's current plan

ForAllScope(the plan's products)

the product's rating = "AAA"

 

There are several ways of writing these functions - see the Entity and relationship function reference for more detail.

NOTES:

  1. A ForAll statement will evaluate to false if its condition is false for one of the targets of the relationship provided. This applies even when the relationship provided is only partially known.
  2. If there are zero instances of the entity the attribute using the Exists operator will evaluate to false.

Check that a condition returns true for at least one instance of an entity

The existential quantifier must be used when you refer from one entity to another entity in a "to-many" relationship, AND you need to determine whether any members of the target entity group need to satisfy the rule. This quantifier works in much the same way across entities as the 'or' operator does across attributes. This means that only one instantiation of the entity must be true for the attribute using the operator to be true.

 

There are two types of entity function that are used as existential quantifiers:

 

1. Exists - this function is used where there is only one condition (ie the rule only refers to one relationship). For example, you could have the following rule where 'the family' is an entity (the source entity), 'the child' is an entity (the target entity), and 'the children' is the relationship between the entities (the relationship text).

 

the family is eligible for the benefit if

Exists(the children, the child is a qualifying child)

 

2. Exists Scope - this function is used where there are one or more conditions (eg when you want to reason across several different relationships in the one rule). For example, you could have the following rule where a customer entity has a one-to-one relationship to a plan entity (the customer's current plan) which has an inferred many-to-many relationship to specific products (the plan's products).

 

the customer has incompatible products if

ForScope(the customer's current plan)

ExistsScope(the plan's products)

the plan's network <> the product's network


There are several ways of writing these functions - see the Entity and relationship function reference for more detail.

NOTES:

  1. An Exists statement will evaluate to true if its condition is true for one of the targets of the relationship provided. This applies even when the relationship provided is only partially known.
  2. If there are zero instances of the entity the attribute using the For All operator will evaluate to true.

TIP: To see a simple example of a rulebase with a many-to-many relationship, open and run the Parents And Children example rulebase project provided in the Examples folder in the Oracle Policy Modeling installation folder.

Refer to entities connected by a to-one relationship

When you refer from one entity to another entity in a "to-one" relationship, you need to use a particular syntax to connect the two entities together. There are two types of entity functions used for this purpose.

1. For - this function is used where there is only one condition (ie the rule only refers to one relationship). For example, you could have the following rule where 'the child' is an entity (the source entity), 'the school' is an entity (the target entity), and 'the child's school' is the many-to-one relationship between the entities (the relationship text).

 

the child has a day off school if

For(the child's school, the school is closed)

 

2. For Scope - this function is used where there are one or more conditions (eg when you want to reason across several different relationships in the one rule). For example, you could have the following rule where a customer entity has a one-to-one relationship to a plan entity (the customer's current plan) which has an inferred many-to-many relationship to specific products (the plan's products).

 

the customer has a premium product if

ForScope(the customer's current plan)

ExistsScope(the plan's products)

the product's cost per month > 200

 

There are several ways of writing these functions - see the Entity and relationship function reference for more detail.

 

NOTE: This syntax does not need to be used when referring to a parent relationship in the entity's containment relationships. For example, if an entity "the child" is contained within an entity "the parent", you could write the following rule without needing to refer to the containment relationship explicitly:

the child is happy if

the parent is happy

Compare entities within the same relationship

To compare entities within the same relationship, you need to add an alias to the entities involved. Aliasing allows you to provide an alternative name used to refer to an entity instance. For more information, see Remove ambiguity when reasoning about more than one instance of the same entity.

Count the number of instances of an entity

To count the number of instances there are of an entity, you use the Instance Count function. The syntax for this function is:

 

For example, the Instance Count function could be used to determine the number of children belonging to the claimant:

the number of the claimant's children = InstanceCount(the children)

(For this rule to compile the following entities and relationship must be included in a properties files in the project: an entity 'the claimant' , an entity 'the child' and a one-to-many relationship 'the children'.)= InstanceSum(the children, the Child Care Benefit amount for the child)

 

The function returns a value of 4 for the following data: 

 

the child
Anthony
Peter
Rebecca
Fiona

Get the highest/most recent value of an entity-level variable

To obtain the highest or most recent value of an entity-level variable for all instances of the entity, you use the Instance Maximum function. The syntax for this function is:

 

For example, the Instance Maximum function could be used to determine the highest bank balance of the claimant's children:

the highest bank balance of the claimant's children = InstanceMaximum(the children, the child's bank balance)

(For this rule to compile the following entities and relationship must be included in a properties files in the project: an entity 'the claimant' , an entity 'the child' and a one-to-many relationship 'the children'.

 

The function returns a value of $175 for the following data: 

 

the child the child's bank balance
Annabel $50
Katrina $175
Mike $120

Get the lowest/least recent value of an entity-level variable

To obtain the lowest or least recent value of an entity-level variable for all instances of the entity, you use the Instance Minimum function. The syntax for this function is:

 

For example, the Instance Minimum function could be used to determine the lightest of the claimant's children:

the lightest of the claimant's children = InstanceMinimum(the children, the child's weight in kilograms)

(For this rule to compile the following entities and relationship must be included in a properties files in the project: an entity 'the claimant' , an entity 'the child' and a one-to-many relationship 'the children'.)

 

The function returns a value of 15 for the following data: 

 

the child the child's weight in kilograms
Harry 15
Sharon 30
Fran 45

Add up numerical values gathered from each instance of an entity

To obtain the sum of all instances of an entity-level variable, you use the Instance Sum function. The syntax for this function is:

 

For example, the Instance Sum function could be used to determine the total Child Care Benefit payable to the claimant:

the total Child Care Benefit payable to the claimant = InstanceSum(the children, the Child Care Benefit amount for the child)

(For this rule to compile the following entities and relationship must be included in a properties files in the project: an entity 'the claimant' , an entity 'the child' and a one-to-many relationship 'the children'.)

 

The function returns a value of $900 for the following data: 

 

the child the Child Care Benefit amount for the child
Mary $500
Sam $250
Lizzie $150

 

See also: