REWERSE RIF Core Condition Language Extension Proposal

REWERSE RIF Core Condition Language Extension Proposal

Editors: Adrian Giurca, Gerd Wagner (REWERSE Working Group I1)
Date: October 31, 2006

Motivation

The distinction between objects and data values (denoted by object- and data-valued terms such as object names/IDs and data literals) has a long tradition in computer science. It exists both in UML/OCL and in RDF(S)/OWL/ SWRL. Moreover, many important languages on the market like ILOG JRules, Blaze Advisor Rules, JBoss Rules, Oracle Business Rules consider it. However, there are also rule languages that don't support this distinction: Prolog, F-Logic, Jess, Jena2 Rules. Our proposal is to allow (but not require) typing both for terms and atoms. For typed terms the RDF/OWL distinction between object-valued and data-valued terms is adopted. The possibility of having untyped terms and untyped atoms is retained for compatibility with languages that don't support the distinction between data values and objects.

Rule Vocabularies

EBNF

Vocabulary           ::= (GenericEntityName | ObjectName | TYPE | PREDICATE | FUNCTION)*
GenericEntityName    ::= 'GenEntityName(' genEntityName ')'
ObjectName           ::= 'OName(' objectID classID? ')'
genEntityName        ::= xs:QName | xs:anyURI
objectID             ::= xs:QName | xs:anyURI

TYPE                 ::= ObjectType | Datatype
ObjectType           ::= 'Class(' classID superClass* ')'
Datatype             ::= 'Datatype(' datatypeID ')' 
superClass           ::= 'superClass(' classID ')'
classID              ::= xs:QName | xs:anyURI
datatypeID           ::= xs:QName | xs:anyURI

PREDICATE            ::= PROPERTY | GenericPredicate | DataTypePredicate | AssociationPredicate
 
PROPERTY             ::= ReferenceProperty | Attribute
ReferenceProperty    ::= 'ReferenceProperty(' refPropID domain objectRange ')'
Attribute            ::= 'Attribute(' attrID domain dataRange ')'
domain               ::= 'domain(' classID ')'
objectRange          ::= 'range(' classID ')'
dataRange            ::= 'range(' datatypeID ')'
refPropID            ::= xs:QName | xs:anyURI
attrID               ::= xs:QName | xs:anyURI

GenericPredicate     ::= 'GRel(' gRelID arity? ')'
genRelID            ::= xs:QName | xs:anyURI
arity                ::= xs:positiveInteger

DataTypePredicate    ::= 'DataTypePredicate(' dataPredID argDatatype* ')'
argDatatype          ::= 'argDatatype(' datatypeID ')'
dataPredID           ::= xs:QName | xs:anyURI

AssociationPredicate ::= 'AssocPredicate(' assocPredID argObjType argObjType argType+ ')'
assocPredID          ::= xs:QName | xs:anyURI
argObjType           ::= 'argObjType(' classID ')'
argType              ::= 'argType(' TYPEID ')'
TYPEID               ::= classID | datatypeID

FUNCTION             ::= GenericFunction | DatatypeFunction | PROPERTY | OPERATION
GenericFunction      ::= 'GFun(' gFunID arity? ')'
gFunID               ::= xs:QName | xs:anyURI

DatatypeFunction     ::= 'DatatypeFunction(' dataFunID argDatatype* ')'
dataFunID            ::= xs:QName | xs:anyURI
argDatatype          ::= 'argDatatype(' datatypeID ')'

OPERATION            ::= ObjectOperation | DataOperation
ObjectOperation      ::= 'ObjectOperation(' objOpID contextType? argType* returnObjType ')'
DataOperation        ::= 'DataOperation(' dataOpID contextType? argType* returnDatatype ')'
objOpID              ::= xs:QName | xs:anyURI
dataOpID             ::= xs:QName | xs:anyURI
contextType          ::= 'contextType(' classID ')'
returnObjType        ::= 'returnType(' classID ')'
returnDatatype       ::= 'returnType(' datatypeID ')'

Typed and untyped individual constants

GenericEntityName
The concept of untyped individual constants/names.
//abc is an untyped constant
GenericEntityName(abc)
XML Syntax
<GenericEntityName genEntityName="abc"/>
ObjectName
The concept of typed object (corresponding to an OWL individual)
//John is a Person
OName( ex:John ex:Person)
XML Syntax
<OName objectID="ex:John" classID="ex:Person"/> 

Classes and datatypes

TYPE
The abstract concept of TYPE is partitioned into object types (classes) and datatypes.
// Defining class Boy 
Class( ex:Boy superClass(ex:Male) superClass(ex:Child))
XML Syntax
<Class classID="ex:Boy">
  <superclass classID="ex:Male"/>
  <superclass classID="ex:Child"/>
</Class>  

Predicates

The abstract concept of PREDICATE is partitioned into generic predicates, properties, datatype predicates and associations. Properties are either attributes, if they are data-valued, or reference properties, if they are object-valued. We distinguish the following kinds of predicates:

ReferenceProperty
// parent is a reference property of the class Person
ReferenceProperty(ex:parent domain(ex:Person) range(ex:Person))
XML Syntax
<ReferenceProperty referencePropertyID="ex:parent" >
 <domain classID="ex:Person" /> 
 <range classID="ex:Person"/> 
</ReferenceProperty>
Attribute
// age is a positive integer attribute of the class Person
Attribute(ex:age domain(ex:Person) range(xs:positiveInteger))
XML Syntax
<Attribute attributeID="ex:age">
 <domain classID="ex:Person"/>
 <range datatypeID="xs:positiveInteger"/>
</Attribute>
GenericPredicate
// p is a generic predicate of arity 3 
GRel(p 3) 
XML Syntax
<GRel gRelID="p" arity="3"/> 
DatatypePredicate
// greaterThan is a DatatypePredicate
DatatypePredicate(ex:greaterThan argDatatype(xs:float) argDatatype(xs:float))

XML Syntax

<DatatypePredicate(dataPredID="ex:greaterThan">
 <argDatatype datatypeID="xs:float"/>
 <argDatatype datatypeID="xs:float"/>
</DatatypePredicate>
AssociationPredicate
// isAssignedTo is an AssociationPredicate between Branch and Rental
AssociationPredicate( eur:isAssignedTo argObjType(eur:Branch) argObjType(eur:Rental))
XML Syntax
<AssociationPredicate assocPredID="eur:isAssignedTo">
 <argObjType classID="eur:Branch"/>
 <argObjType classID="eur:Rental"/>
</AssociationPredicate>  

Functions

FUNCTION. The abstract concept of FUNCTION GenericFunction, DatatypeFunction, PROPERTY, OPERATION

GenericFunction
The standard logic concept of untyped function.
// f is a function with arity 3
GFun(f 3)
XML Syntax
<GFun gFunID="f" arity="3"/>
DatatypeFunction
A datatype-specific function that takes data terms as arguments and evaluates to a data value.
// substr is a DatatypeFunction
DatatypeFunction(ex:substr argDatatype(xs:string) argDatatype(xs:int) argDatatype(xs:int))

XML Syntax

<DatatypeFunction dataFunID="ex:substr">
 <argDatatype datatypeID="xs:string"/>
 <argDatatype datatypeID="xs:int"/>
 <argDatatype datatypeID="xs:int"/>
</DatatypeFunction> 
ObjectOperation
A special type of a user-defined function that corresponds to an object-valued operation in a UML class model (UML vocabulary).It may have arguments in the form of any value (either objects and/or data values) and returns an object.
// getNthAncestor is an ObjectOperation of class Person 
ObjectOperation (ex:getNthAncestor contextType(ex:Person) argType(xs:positiveInteger) returnType(ex:Person))
XML Syntax
<ObjectOperation objOpID="eur:calculateMonthlyPayment">
 <contextType classID="eur:Person"/>
 <argType datatypeID="xs:positiveInteger"/>
 <returnType classID="ex:Person"/>
</ObjectOperation> 
DataOperation
A special type of a user-defined function that corresponds to a data-valued operation in a UML class model (UML vocabulary).It may have arguments in the form of any value (either objects and/or data values) and returns a data literal.
// calculateMonthlyPayment is a DataOperation of the class em>Loan
DataOperation (eur:calculateMonthlyPayment contextType(eur:Loan) argType(xs:positiveInteger) returnType(xs:float))
XML Syntax
<DataOperation dataOpID="eur:calculateMonthlyPayment">
 <contextType classID="eur:Loan"/>
 <argType datatypeID="xs:positiveInteger"/>
 <returnType datatypeID="xs:float"/>
</DataOperation>  

Terms

TERM   ::= INDIVIDUALNAME | VAR | FTERM

Individual Names

Instead of the ambiguous and hard to read abbreviations CON and DATA we propose to use the more verbosenon-terminals INDIVIDUALNAME and DATALITERAL.

INDIVIDUALNAME    ::= GenericEntityName | ObjectName | DATALITERAL
DATALITERAL       ::= PlainLiteral | TypedLiteral
PlainLiteral      ::= 'PLit(' lexicalValue languageTag? ')'
TypedLiteral      ::= 'TLit(' lexicalValue datatypeID ')'
objectID          ::= xs:QName | xs:anyURI
classID           ::= xs:QName | xs:anyURI
datatypeID        ::= xs:QName | xs:anyURI

where GenericEntityName is the concept of untyped individual constants/names, ObjectName is the concept of typed individual (corresponding to an OWL individual, for example) and PlainLiteral and TypedLiteral correspond to RDF's plain literal and typed literal (i.e. languageTag is as in [RFC-3066] and lexicalValue being a Unicode [UNICODE] string, which should be in Normal Form C [NFC]). xs:NCName, xs:anyURI and xs:QName are XML Schema datatypes. classID is a reference to the vocabulary class of the ObjectName.

Variables

Following SWRL's abstract syntax we propose to distinguish between object variables i.e. variables that denote objects and data variables i.e. variables that denote data values.

VAR        ::= GVar | OVar | DVar
GVar       ::= 'GVar(' name ')'
OVar       ::= 'OVar(' name classID? ')'
DVar       ::= 'DVar(' name datatypeID? ')'
name       ::= xs:NCName

where OVar stands for object variable, DVar stands for data variable, GVar stands for generic (or untyped) variable. classID and datatypeID are optional references to the corresponding vocabulary elements (classes respectively datatypes). Notice that imposing the character '?' as starting character for a variable name is a non necessary (see languages like Java for example).

Function Terms

In addition to generic function term concept from standard predicate logic, we propose also properties as functions, user-defined functions and datatype (or built-in) functions. All these types of functions are constituents of object-oriented programming, modeling and rule languages. Following OO terminology, user-defined functions are called operations, data-valued properties are called attributes and object-valued properties are called reference properties(because they refer to an object).

FTERM  ::= GTERM | OTERM | DTERM
GTERM  ::= GenericEntityName | GVar | GFTerm
GFTerm ::= GFun '(' GTERM* ')'

OTERM                  ::= ObjectName | OVar | OFTERM
OFTERM                 ::= ObjectOperationFTerm | ReferencePropertyFTerm
ObjectOperationFTerm   ::= 'ObjectOperationTerm(' objOpID contextArg? argument* ')'
context                ::= 'context(' OTERM ')'
argument               ::= 'argument(' TERM ')'
ReferencePropertyFTerm ::= 'ReferencePropertyFTerm(' refPropID OTERM ')'

DTERM              ::= DATALITERAL | DVar | DFTERM
DFTERM             ::= DataOperationFTerm | AttributeFTerm | DatatypeFTerm 
DataOperationFTerm ::= 'DataOperationFTerm(' dataOpID  context? argument* ')'
AttributeFTerm     ::= 'AttributeFTerm(' attrID OTERM ')'
DatatypeFTerm      ::= 'DatatypeFunctionTerm(' dataFunID DTERM* ')'
dataOpID           ::= xs:QName | xs:anyURI
attrID             ::= xs:QName | xs:anyURI
dataFunID          ::= xs:QName | xs:anyURI

Atoms

We follow SWRL distinction between different types of atoms, because it formalizes the types of atomic statements that are implicit in OO languages. In addition to SWRL object classification atoms, property atoms and object equality atoms, we propose to include association atoms, which support n-ary relations.

ATOM   ::= GAtom | OATOM | DATOM
GAtom  ::= 'GenericAtom(' gRelID GTERM* ')' | GTERM '=' GTERM
gRelID ::= xs:QName | xs:anyURI

OATOM                 ::= OClassificationAtom | PROPERTYATOM | AssociationAtom | ObjectEqualityAtom 

OClassificationAtom   ::= 'ObjectClassificationAtom(' classID  OTERM ')'

PROPERTYATOM          ::= ReferencePropertyAtom | AttributionAtom
ReferencePropertyAtom ::= 'ReferencePropertyAtom(' refPropID OTERM OTERM ')'
AttributionAtom       ::= 'AttributionAtom(' attrID OTERM DTERM ')'

AssociationAtom       ::= 'AssociationAtom(' assocID OTERM OTERM TERM+ ')'
ObjectEqualityAtom    ::= OTERM '=' OTERM 

DATOM                 ::= DClassificationAtom | DatatypePredicateAtom
DClassificationAtom   ::= 'DataClassificationAtom(' datatypeID DTERM ')'
DatatypePredicateAtom ::= 'DatatypePredicateAtom(' dataPredID DTERM+ ')'

The equality between two data terms must follow the RDF concept of literal equality and is defined by datatype-specific equality predicates.

Examples

At the time of this proposal the following existent languages have been investigated:

Object and Data Classification Atoms

The concepts of object classification atom and data classification atom already exist in OWL/SWRL and UML/OCL also in specific rule languages. The REWERSE Rule Markup WG develops such XML syntax. All examples below use a possible XML syntax for the RIF Core condition language with the proposed extension (adopted from R2ML).

// cust is a GoldCustomer
RIF:   ObjectClassificationAtom( ex:GoldCustomer OVar(cust ex:Customer)) 
SWRL:  ex:GoldCustomer( I-variable(cust)) 
UML/OCL: cust : GoldCustomer 
JRules:  ?cust : GoldCustomer();
Blaze:  cust is any GoldCustomer
JBoss Rules: cust : GoldCustomer()
F-Logic:  Cust : GoldCustomer.

XML Syntax:

<ObjectClassificationAtom classID="ex:GoldCustomer">
 <OVar name="cust" classID="ex:Customer"/>
</ObjectClassificationAtom>
// distance is an Integer
RIF:     DataClassificationAtom( xs:integer DVar(distance)) 
SWRL:    Integer (D-variable(distance))
UML/OCL: distance : Integer 
JRules:  ?distance : int;
Blaze:   distance is any Integer 
JBoss Rules: distance : int
F-Logic:  -

XML Syntax:

<DatatClassificationAtom datatypeID="xs:Integer">
 <DVar name="distance"/>
</DataClassificationAtom>

Property Atoms: Properties can be both relations and functions

Property atoms are common in OWL/SWRL and UML/OCL. Both languages distinguish between object-valued properties and data-valued properties. While a property is a relation in OWL/SWRL, it is a function in UML/OCL. In RIF, a property can be considered both a relation and a function. Consequently, a relational property atom can be rewritten as an equality atom, as the examples below show. In the case of an attribution (data-valued property) atom, the equality predicate is provided by the respective datatype. In our example below, we reuse the SWRL built-in equality predicate.

Attribution Atoms

// the age of cust is 40
RIF:         AttributionAtom( ex:age OVar(cust) TLit(40 xs:int)) 
RIF:         swrlb:equal( ex:age(context(OVar(cust))) TLit(40 xs:int))  
SWRL:        age( I-variable(cust), '40' ) 
Jena 2:      (?cust ex:age "40"^^xs:int)
UML/OCL:     cust.age = 40 
F-Logic:     cust:Customer[age -> '40']
JRules:      ?cust : Customer(age==40);
Blaze:       cust is any Customer
JBoss Rules: cust : Customer(age == 40) 

XML Syntax

// the property ex:age as a relation
<AttributionAtom attrID="ex:age" >
 <OVar name="sCart" classID="ex:ShoppingCart"/>
 <TLit lexicalValue="40" datatypeID="xs:integer"/>
</AttributionAtom>
// the property ex:age as a function
<DatatypePredicateAtom dataPredID="swrlb:equal">
 <AttributeFTerm attrID="ex:age">
   <OVar name="cust" classID="ex:Customer"/>
 </AttributeFTerm>
 <TLit lexicalvalue="40" datatypeID="xs:int"/>
</DatatypePredicateAtom>

Reference Property Atoms

// the customer assigned to ShoppingCart sCart is cust
RIF: ReferencePropertyAtom( ex:customer OVar(sCart ex:ShoppingCart) OVar(cust))
RIF: ReferencePropertyFunctionTerm(ex:customer OVar(sCart ex:ShoppingCart)) = OVar(cust)
SWRL:       customer(I-variable(sCart) I-variable(cust)) 
Jena 2:     (?sCart ex:customer ?cust)
UML/OCL:    sCart.customer = cust;
F-Logic:     sCart:ShoppingCart[customer -> Cust]
JRules:     sCart : ShoppingCart(customer == cust);
Blaze:      sCart is any ShoppingCart such that 
            sCart.customer = cust is any Customer
JBoss Rules: sCart:ShoppingCart(customer == cust);

XML Syntax

<ReferencePropertyAtom refPropID="ex:customer">
 <OVar name="sCart" classID="ex:ShoppingCart"/>
 <OVar name="cust" classID="ex:Customer"/>
</ReferencePropertyAtom>

Notice that FLogic does not distinguish between object-valued properties and data-valued properties but provides a generic concept of property in the form of an F-molecule. FLogic also encodes the cardinality of the value of a property (using ->> for multivalued properties).

Generic Atoms

The GAtom construct is supposed to be used when interchange with languages that do not distinguish between objects and data, such as Prolog and Jess:

RIF:   GenericAtom( geometry:inbetween GVar(point1), GVar(point2), GVar(point3))
Prolog: inbetween( Point1, Point2, Point3)
JESS:  (inbetween ?point1 ?point2 ?point3)

XML Syntax

<GAtom gRelID="geometry:inbetween">
 <GVar name="point1"/>
 <GVar name="point2"/>
 <GVar name="point3"/>
</GAtom>