Production Rules in R2ML

We consider the following production rule extracted from UServ Product Derby 2005 Use Case:

 If young driver and married and not located in CA, NY or VA, 
 then increase premium by $300.

The R2ML markup for this rule is depicted below:

 1  <r2ml:RuleBase xmlns:r2ml="http://www.rewerse.net/I1/2006/R2ML" xmlns:dc="http://purl.org/dc/elements/1.1/" 
                   xmlns:userv="http://www.businessrulesforum.com/2005/userv#"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                   xsi:schemaLocation="http://www.rewerse.net/I1/2006/R2ML http://oxygen.informatik.tu-cottbus.de/R2ML/0.5/R2ML.xsd"
 
 2   <r2ml:ProductionRuleSet r2ml:ruleSetID="UServProductionRulesSet" 
                             r2ml:externalVocabulary="http://oxygen.informatik.tu-cottbus.de/rewerse-i1/files/UServ_DP.owl" 
                             r2ml:externalVocabularyLanguage="OWL">
  
 3    <r2ml:ProductionRule r2ml:ruleID="DP_03">
 4     <r2ml:Documentation>
 5      <r2ml:RuleText r2ml:textFormat="plain">
 6       <[!CDATA[
            If young driver and married and not located in CA, NY or VA, 
            then increase premium by $300.
         ]]>
 7      </r2ml:RuleText>
 8     </r2ml:Documentation>

 9     <r2ml:conditions>
10      <r2ml:AttributionAtom r2ml:attribute="userv:YoungDriver.maritalStatus">
11       <r2ml:subject>
12        <r2ml:ObjectVariable r2ml:name="driver" r2ml:class="userv:YoungDriver"/>
13       </r2ml:subject>
14       <r2ml:dataValue>
15        <r2ml:TypedLiteral r2ml:lexicalValue="married" r2ml:datatype="xs:string"/>
16       </r2ml:dataValue>
17      </r2ml:AttributionAtom>

18      <r2ml:qf.Disjunction>
19       <r2ml:AttributionAtom r2ml:attribute="userv:YoungDriver.usState" r2ml:isNegated="true">
20        <r2ml:subject>
21         <r2ml:ObjectVariable r2ml:name="driver" r2ml:class="userv:YoungDriver"/>
22        </r2ml:subject>
23        <r2ml:dataValue>
24         <r2ml:TypedLiteral r2ml:lexicalValue="CA" r2ml:datatype="xs:string"/>
25        </r2ml:dataValue>
26       </r2ml:AttributionAtom>
27       <r2ml:AttributionAtom r2ml:attribute="userv:YoungDriver.usState" r2ml:isNegated="true">
28        <r2ml:subject>
29         <r2ml:ObjectVariable r2ml:name="driver" r2ml:class="userv:YoungDriver"/>
30        </r2ml:subject>
31        <r2ml:dataValue>
32         <r2ml:TypedLiteral r2ml:lexicalValue="NY" r2ml:datatype="xs:string"/>
33        </r2ml:dataValue>
34       </r2ml:AttributionAtom>

35       <r2ml:AttributionAtom r2ml:attribute="userv:YoungDriver.usState" r2ml:isNegated="true">
36        <r2ml:subject>
37         <r2ml:ObjectVariable r2ml:name="driver" r2ml:class="userv:YoungDriver"/>
38        </r2ml:subject>
39        <r2ml:dataValue>
40         <r2ml:TypedLiteral r2ml:lexicalValue="VA" r2ml:datatype="xs:string"/>
41        </r2ml:dataValue>
42       </r2ml:AttributionAtom>

43      </r2ml:qf.Disjunction>
44     </r2ml:conditions>

45     <r2ml:producedActionExpr>
46      <r2ml:UpdateActionExpr r2ml:property="userv:VehicleInsurancePolicy.premium">
47       <r2ml:contextArgument>
48        <r2ml:ObjectVariable r2ml:name="vehicleInsurancePolicy" r2ml:class="userv:VehicleInsurancePolicy"/>
49       </r2ml:contextArgument>
50       <r2ml:DatatypeFunctionTerm r2ml:datatypeFunction="op:numeric-add">
51        <r2ml:dataArguments>
52         <r2ml:AttributeFunctionTerm r2ml:attribute="userv:VehicleInsurancePolicy.premium">
53          <r2ml:contextArgument>
54           <r2ml:ObjectVariable r2ml:name="vehicleInsurancePolicy" r2ml:class="userv:VehicleInsurancePolicy"/>
55          </r2ml:contextArgument>
56         </r2ml:AttributeFunctionTerm>
57         <r2ml:TypedLiteral r2ml:lexicalValue="300" r2ml:datatype="xs:integer"/>
58        </r2ml:dataArguments>
59       </r2ml:DatatypeFunctionTerm>
60      </r2ml:UpdateActionExpr>
61     </r2ml:producedActionExpr>

62    </r2ml:ProductionRule>

63   </r2ml:ProductionRuleSet>
64  </r2ml:RuleBase>

The r2ml:RuleBase element (see Line 1) is the parent of one or many rule sets. A r2ml:RuleBase element can contains different kibd of rule sets: derivation, production, reaction rule sets and so on. All namespaces which must be available in all rules are declared here.

A production rule set is declared by the element r2ml:ProductionRuleSet (see Line 2). This element contains three optional attributes:

  • r2ml:ruleSetID - is the name of the rule set. In our example this is UServProductionRulesSet
  • r2ml:externalVocabulary - represent an URI of an external vocabulary. In our example we use OWL to describe the vocabulary.
  • r2ml:externalVocabularyLanguage - refers the language of the external vocabulary.

Every production rule is enclosed into a r2ml:ProductionRule element (see line 3). An optional element r2ml:Documentation (Lines 4-8) can contains elements which enclose the rule text (Lines 5-7) and the representation of the rule in a specific rules language.

The r2ml:conditions (Lines 9-44) can contains one or more atoms. If nothing is specified, then atoms are connected by default by conjunction. Disjunction between atoms can be expressed using r2ml:qf.Disjunction (Lines 18-43).

The rule contains several r2ml:AttributionAtom elements (Lines 10-17, 19-26, 27-34, 35-42). The value of the mandatory attribute r2ml:attribute is the name of the property to which we need to refer. It can contains also the attribute r2ml:isNegated with true (see Line 35) which by default is set to false.

The r2ml:AttributionAtom contains a r2ml:subject element which enclose the object to which we refer. This can be expressed for example by an r2ml:ObjectVariable (i.e. Line 21). The value of the property is referred by a r2ml:dataValue. In this example the value is encoded by a r2ml:TypedLiteral element (i.e. Line 24).

The r2ml:producedActionExp represent the rule head. Several actions are suported in this section. The example use a r2ml:UpdateActionExpre action. This preform an update of the property referred by the value of the r2ml:property attribute. The r2ml:contextArgument contains the object which contains that property. In this example it is expressed by a r2ml:ObjectVariable.

This action must update the premium property of the vehicleInsuranceProperty object increasing the actual value by 300 (Lines 50-59). The sum is expressed with the help of the r2ml:DatatypeFunctionTerm element and it's property r2ml:datatypeFunction which has the value op:numeric-add. This calculate the new value of the premium property.

The rule use an external vocabulary, described using OWL:

 1  <rdf:RDF xmlns:owl="http://www.w3.org/2002/07/owl#"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:userv="http://www.businessrulesforum.com/2005/userv#"> 

 2   <owl:Class rdf:about="http://www.businessrulesforum.com/2005/userv#Driver"/>
  
 3   <owl:Class rdf:about="http://www.businessrulesforum.com/2005/userv#YoungDriver">
      <rdfs:subClassOf rdf:resource="http://www.businessrulesforum.com/2005/userv#Driver">
 4   </owl:Class>
  
 5   <owl:Class rdf:about="http://www.businessrulesforum.com/2005/userv#InsurancePolicy"/>
  
 6   <owl:Class rdf:about="http://www.businessrulesforum.com/2005/userv#VehicleInsurancePolicy">
 7    <rdfs:subClassOf rdf:resource="http://www.businessrulesforum.com/2005/userv#InsurancePolicy">
 8   </owl:Class>
  
 9   <owl:DatatypeProperty rdf:about="http://www.businessrulesforum.com/2005/userv#maritalStatus">
10    <rdfs:comment>The marital status of the driver</rdfs:comment>
11    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
12    <rdfs:domain rdf:resource="http://www.businessrulesforum.com/2005/userv#Driver"/>
13   </owl:DatatypeProperty>
  
14   <owl:DatatypeProperty rdf:about="http://www.businessrulesforum.com/2005/userv#usState">
15    <rdfs:comment>The US state where the client live.</rdfs:comment>
16    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
17    <rdfs:domain rdf:resource="http://www.businessrulesforum.com/2005/userv#Driver"/>
18   </owl:DatatypeProperty>

19   <owl:DatatypeProperty rdf:about="http://www.businessrulesforum.com/2005/userv#premium">
20    <rdfs:comment>The value of the insurance premium.</rdfs:comment>
21    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#double"/>
22    <rdfs:domain rdf:resource="http://www.businessrulesforum.com/2005/userv#InsurancePolicy"/>
22   </owl:DatatypeProperty>
  
19  </rdf:RDF>

The OWL vocabulary contains all structures which appears in that rule. It define Driver, YoungDriver, InsurancePolicy and VehicleInsurancePolicy classes. Also, properties of these classes which appears in the rule are defined: maritalStatus, usState and premium.

Production Rules