graphic with four colored squares
Cover page images (keys)

Rule Interchange Format (RIF)

Sandro Hawke (sandro@w3.org), RIF staff contact
For HCLS, 3 September 2009

So Many Rule Systems

It is a way of programming, and a way of not programming

Semantic Web Perspective

What does RIF do for the Semantic Web?

Business Rules Perspective

Thinking in terms of the business

Diversity

Simple rule systems vs cutting-edge research

Dream vs Reality

The Plan

Start with a common core

  1. Find the thing that rule systems have in common (60%)
  2. Standardize that ("RIF Core")
  3. Then work on extensions

Core must be truly extensible

Some details

Focus on translating to/from RIF

Extensions may be incompatible

Thus "format" instead of "language"

The People Involved

Organizations

RIF: XML Syntax for Rules

<!DOCTYPE Document [
  <!ENTITY ppl  "http://example.com/people#">
  <!ENTITY cpt  "http://example.com/concepts#">
  <!ENTITY dc   "http://purl.org/dc/terms/">
  <!ENTITY rif  "http://www.w3.org/2007/rif#">
  <!ENTITY func "http://www.w3.org/2007/rif-builtin-function#">
  <!ENTITY pred "http://www.w3.org/2007/rif-builtin-predicate#">
  <!ENTITY xs   "http://www.w3.org/2001/XMLSchema#">
]>

<Document 
    xmlns="http://www.w3.org/2007/rif#"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xs="http://www.w3.org/2001/XMLSchema#">
  <payload>
   <Group>
    <id>
      <Const type="&rif;iri">http://sample.org</Const>
    </id>
    <meta>
      <Frame>
        <object>
          <Const type="&rif;local">pd</Const>
        </object>
        <slot ordered="yes">
          <Const type="&rif;iri">&dc;publisher</Const>
          <Const type="&rif;iri">http://www.w3.org/</Const>
        </slot>
        <slot ordered="yes">
          <Const type="&rif;iri">&dc;date</Const>
          <Const type="&xs;date">2008-04-04</Const>
        </slot>
      </Frame>
    </meta>
    <sentence>
     <Forall>
       <declare><Var>item</Var></declare>
       <declare><Var>deliverydate</Var></declare>
       <declare><Var>scheduledate</Var></declare>
       <declare><Var>diffduration</Var></declare>
       <declare><Var>diffdays</Var></declare>
       <formula>
         <Implies>
           <if>
             <And>
               <formula>
                 <Atom>
                   <op><Const type="&rif;iri">&cpt;perishable</Const></op>
                   <args ordered="yes"><Var>item</Var></args>
                 </Atom>
               </formula>
               <formula>
                 <Atom>
                   <op><Const type="&rif;iri">&cpt;delivered</Const></op>
                   <args ordered="yes">
                     <Var>item</Var>
                     <Var>deliverydate</Var>
                     <Const type="&rif;iri">&ppl;John</Const>
                   </args>
                 </Atom>
               </formula>
               <formula>
                 <Atom>
                   <op><Const type="&rif;iri">&cpt;scheduled</Const></op>
                   <args ordered="yes">
                     <Var>item</Var>
                     <Var>scheduledate</Var>
                   </args>
                 </Atom>
               </formula>
               <formula>
                 <Equal>
                   <left><Var>diffduration</Var></left>
                   <right>
                     <External>
                       <content>
                         <Expr>
                           <op><Const type="&rif;iri">&func;subtract-dateTimes</Const></op>
                           <args ordered="yes">
                             <Var>deliverydate</Var>
                             <Var>scheduledate</Var>
                           </args>
                         </Expr>
                       </content>
                     </External>
                   </right>
                 </Equal>
               </formula>
               <formula>
                 <Equal>
                   <left><Var>diffdays</Var></left>
                   <right>
                     <External>
                       <content>
                         <Expr>
                           <op><Const type="&rif;iri">&func;days-from-duration</Const></op>
                           <args ordered="yes">
                             <Var>diffduration</Var>
                           </args>
                         </Expr>
                       </content>
                     </External>
                   </right>
                 </Equal>
               </formula>
               <formula>
                 <External>
                   <content>
                     <Atom>
                       <op><Const type="&rif;iri">&pred;numeric-greater-than</Const></op>
                       <args ordered="yes">
                         <Var>diffdays</Var>
                         <Const type="&xs;integer">10</Const>
                       </args>
                     </Atom>
                   </content>
                 </External>
               </formula>
             </And>
           </if>
           <then>
             <Atom>
               <op><Const type="&rif;iri">&cpt;reject</Const></op>
               <args ordered="yes">
                 <Const type="&rif;iri">&ppl;John</Const>
                 <Var>item</Var>
               </args>
             </Atom>
           </then>
         </Implies>
       </formula>
     </Forall>
    </sentence>
    <sentence>
     <Forall>
       <declare><Var>item</Var></declare>
       <formula>
         <Implies>
           <if>
             <Atom>
               <op><Const type="&rif;iri">&cpt;unsolicited</Const></op>
               <args ordered="yes"><Var>item</Var></args>
             </Atom>
           </if>
           <then>
             <Atom>
               <op><Const type="&rif;iri">&cpt;reject</Const></op>
               <args ordered="yes">
                 <Const type="&rif;iri">&ppl;Fred</Const>
                 <Var>item</Var>
               </args>
             </Atom>
           </then>
         </Implies>
       </formula>
     </Forall>
    </sentence>
   </Group>
  </payload>
 </Document>

BLD Presentation Syntax

Document(
  Prefix(ppl  <http://example.com/people#>)
  Prefix(cpt  <http://example.com/concepts#>)
  Prefix(dc   <http://purl.org/dc/terms/>)
  Prefix(rif  <http://www.w3.org/2007/rif#>)
  Prefix(func <http://www.w3.org/2007/rif-builtin-function#>)
  Prefix(pred <http://www.w3.org/2007/rif-builtin-predicate#>)
  Prefix(xs   <http://www.w3.org/2001/XMLSchema#>)
  
  (* "http://sample.org"^^rif:iri _:pd[dc:publisher -> "http://www.w3.org/"^^rif:iri
                                      dc:date -> "2008-04-04"^^xs:date] *)
  Group
  (
    Forall ?item ?deliverydate ?scheduledate ?diffduration ?diffdays (
        cpt:reject(ppl:John ?item) :-
            And(cpt:perishable(?item)
                cpt:delivered(?item ?deliverydate ppl:John)
                cpt:scheduled(?item ?scheduledate)
                ?diffduration = External(func:subtract-dateTimes(?deliverydate ?scheduledate))
                ?diffdays = External(func:days-from-duration(?diffduration))
                External(pred:numeric-greater-than(?diffdays 10)))
    )
 
    Forall ?item (
        cpt:reject(ppl:Fred ?item) :- cpt:unsolicited(?item)
    )
  )
)

Other Presentation Syntaxes

Nothing standard... room for experimentation

Prefix ppl <http://example.com/people#>
Prefix cpt  <http://example.com/concepts#>
Prefix dc   <http://purl.org/dc/terms/>
Prefix rif  <http://www.w3.org/2007/rif#>
Prefix func <http://www.w3.org/2007/rif-builtin-function#>
Prefix pred <http://www.w3.org/2007/rif-builtin-predicate#>
Prefix xs   <http://www.w3.org/2001/XMLSchema#>
  
(* lt;http://sample.org> { _:pd dc:publisher lt;http://www.w3.org/>;
                                dc:date "2008-04-04"^^xs:date] } *)
if cpt:perishable(?item) and
   cpt:delivered(?item ?deliverydate ppl:John) and
   cpt:scheduled(?item ?scheduledate) and
   func:days-from-duration(?deliverydate - ?scheduledate) > 10
then cpt:reject(ppl:John ?item).

if   cpt:unsolicited(?item)
then cpt:reject(ppl:Fred ?item).

Slippery slope to "real" rule languages.

A Family of Dialects

But...

Not all engines can implement every feature

Some features (retract and negation) are incompatible

Forward chaining, Backward chaining

So...

Core: common subset

BLD: (basic logic dialect) common subset of Prolog-style languages

PRD: (production rule dialect) common subset of Production Rule languages

Use Case: Vocabulary Mapping

        if { ?x foaf:firstName ?first;
                foaf:surname ?last }
        then
           { ?x foaf:family_name ?last;
                foaf:givenname ?first;
                foaf:name func:string-join(?first " " ?last)
           }

        if { ?x foaf:name ?name } and
           pred:contains(?name, " ")
        then
           { ?x foaf:firstName func:string-before(?name, " ");
                foaf:surname func:string-after(?name, " ")
           }

Use Case: ad hoc Reasoning

        if { ?p rdfs:range ?c.   
             ?x ?p ?y }
        then
           { ?y rdf:type ?c }
        

See OWL 2 RL in RIF

Syntactic Features

Datatypes and Builtins

Most XML Schema 1.1 Datatypes (same subset as OWL 2)

Many xpath-functions, plus a few other things

Status

Planning for "Candidate Recommendation" this month

Expecting about a dozen implementation efforts

Planning for "W3C Recommendation" by end of year.

==> It's stable, but virtually no software yet.