This document is also available in these non-normative formats: PDF version.
This document specifies a reversible mapping (or transformation) from Rule Interchange Format (RIF) XML documents to Resource Description Framework (RDF) graphs. This mapping allows the contents of RIF documents to be interoperably stored and processed as RDF triples, using existing serializations and tools for RDF. When used with the standard mapping from RDF triples to RIF frames, this also provides a "reflection" or "introspection" mechanism, an interoperable way for RIF rules to operate on RIF documents.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
RIF RIF Combination with XML data RIF In RDF (this document) RIF Test Cases XML Schema Datatypes Dependency RIF is defined
to use datatypes defined in the XML Schema Definition Language (XSD) . As of this writing, the latest W3C Recommendation for XSD is version 1.0, with version 1.1 progressing toward Recommendation. RIF has been designed to
take advantage ofthe new datatypes and clearer explanations available in XSD 1.1, but
now those advantages are being partially put on hold. Specifically, until XSD 1.1 becomes
a W3C Recommendation,
elements of RIF which are based
it should be considered optional , as detailed in Datatypes and Builtins, section 2.3 . Uponthe
of XSD 1.1as a W3C Recommendation, those elements will cease to be optional and are to be considered required as otherwise specified. We suggest that for now developers and users follow the XSD 1.1 Last Call Working Draft . Based on discussions between the Schema, RIF and OWL Working Groups, we do not expect any implementation changes will be necessary as XSD 1.1 advances to Recommendation. First Public Working Draft During the development of the RIF XML syntax, there was an awareness of the need for an RDF encoding. There was even a proposal for using a constrained (schema-checkable) RDF/XML serialization as the primary syntax for RIF. The final syntax turned out to be very similar to RDF/XML, making this mapping fairly simple. Looking forward, with the publication (at the same time as this document) of the main RIF deliverables as Recommendations, and the RIF Working Group charter expiring soon, this specification is unlikely to become a full W3C Recommendation during the lifetime of the current Working Group. We expect, instead, that it will be left as a Working Group Note, suitable for use by implementors but without the thorough review it may eventually require if it becomes a focus of significant RIF adoption. Please Comment By 20 July 2010 The Rule Interchange Format (RIF) Working Group seeks public feedback on this First Public Working Draft. Please send your comments to firstname.lastname@example.org ( public archive ). If possible, please offer specific changes to the text that would address your concern. You may also wish to check the Wiki Version of this document and see if the relevant text has already been updated. No Endorsement Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
Table of Contents
The Rule Interchange Format (RIF) [RIF Overview] is an interlingua between rule systems. It is an overlapping family of XML languages (called "dialects") designed for transmitting and storing various kinds of computer-processable rules and related data. Three standard dialects have been defined: RIF Core [RIF Core], RIF Basic Logic Dialect (BLD) [RIF BLD], and RIF Production Rules Dialect (PRD) [RIF PRD]. RIF Core is a sublanguage of BLD and of PRD: every Core document is also a BLD document and a PRD document.
RIF was envisioned [RIF Charter] to be extensible, allowing third parties to define non-standard extensions which could be combined into new dialects, as needed, to support interchange of rule sets which include features not defined in the standard dialects. no general mechanism for extensions has been detailed in the RIF
specifications, however, although The RIF Framework for Logic Dialects (FLD) [RIF FLD] specifies how to create more expressive logic dialects.
The Resource Description Framework (RDF) [RDF] is a standard abstract way to represent data. The units of data in RDF are triples consisting of a subject, property (or predicate), and value (or
object), which are similar to (and compatible with) RIF Frames (see RIF-RDF Combinations [RIF RDF+OWL]). A set of triples can be viewed as a directed labeled graph, where the nodes are subjects and values and the arcs are labeled with property identifiers; we therefore speak of a set of RDF triples as an RDF graph. RDF graphs can be serialized in multiple equivalent syntaxes, including RDF/XML [RDF XML], RDFa [RDFa], and Turtle [Turtle]. RDF can be processed with a wide variety of software tools [RDF Tools].
This specification defines a reversible mapping from RIF syntactic structures to RDF graphs. The definition is presented in
two orderedtables where each row in the tables shows an XML template and a corresponding RDF graph template. The mapping is performed, roughly speaking, by finding the first matching XML template, then producing the corresponding graph. In some cases, the graph will require recursive translations of XML subtrees. The resulting graph has one node, called the focus node, which represents the XML root node, which in RIF Core, BLD, and PRD is rif:Document.
mapping is possible for standard RIF by simply matching the RDF template and generating the corresponding XML. For extended RIF, the mapping is lossy,so the reverse mapping can only done if the translator has extra information.
Note that RDF serializations produced via this mapping are not standard RIF documents and cannot necessarily be understood by RIF implementations.
The rest of this document is structured as follows:
In designing this mapping a few use cases were considered:
The following requirements were taken into account in this design:
Editor's Note: in this current design, the mapping does not use rdf:type triples. This may change in the future. This is Issue 101 . ForRIF syntactic extensions to be properly handled by this
they must use different properties from any existing syntax, and those properties must be required wherever used.for example, if one were adding a new type of formula, "Xor", which was usable wherever "Or" was usable, it could not be merely distinguished by havinga different class element (extn:Xor instead of rif:Or); it would have to replace the rif:formula property inside the rif:Or element with something else, such as extn:xorFormulas. Additionally, where rif:Or allows zero or more rif:formula property elements to occur, the extn:xorFormulas property would have to be defined to occur exactly once. Since the Xor operation needs multiple values, the ordered="yes" mechanism would be used to allow them.
These restrictions are necessary in order to meet the stated requirements. In particular, without these restrictions, a RIF document (in RDF graph form) being transformed by an incomplete reasoner into another RIF document (also in RDF graph form) could produce an unintended and incorrect result just because the reasoning was incomplete. With these restrictions, the result will not match the reverse-mapping until it is sufficiently complete.
The mapping from RIF XML to RDF Graphs is expressed as a function Tr:
Tr(rif-xml-tree) → <focus-node, triples>
For every standard RIF Document, and for certain subtrees of RIF documents and extended RIF documents, Tr maps to the pair of an RDF node and an RDF graph. The node, called the focus node represents the same syntactic element as the root of the given XML tree. The RDF graph is a standard RDF graph, a set of RDF triples, and always contains the focus node. The focus node is usually a fresh blank node, but it might have a IRI label in certain cases, as detailed below.
In this document, the Turtle [Turtle] RDF serialization syntax is used for expressing triples and graphs. Turtle has a very terse syntax for lists, ( item-1 ... item-n ) and for fresh blank nodes and the triples using them as the subject: [ property-1 value-1; ... property-n value-n ]. These constructs allow the mapping to be presented and examples to be shown with relative simplicity.
The mapping is defined recursively, with each application of Tr converting an XML class element to a focus node, with additional triples. Class elements in RIF XML have tags that begin with an uppercase letter and represent a particular syntactic entity. Except for rif:Var and rif:Const class elements (detailed in Table 1, below), all the class elements follow a general form, containing a sequence of property elements, each containing additional class elements. The mapping for these is detailed in Table 2 and Table 3, below.
Editor's Note: In this current design, the mapping does not use rdf:type triples. This may change in the future. This is Issue 101 .For another example of a specification of a mapping to RDF graphs, which may lend insight into how to use this specification, see OWL 2 Mapping to RDF Graphs [OWL2 Mapping].
5.1 Namespaces All standard elements in RIF XML have the namespace " http://www.w3.org/2007/rif# ", and the attributes have no namespace. Extensions are expected to use other namespaces for the elements and are not allowed to introduce new attributes. The
RIF-in-RDF mapping produces RDF graphs that use the same namespace, although they use that namespace name in the normal RDF way (as an IRI prefix) instead of in the XML way (as a disambiguator).
By keeping the namespace the same, transformation software can correctly operate, without modification, on all RIF documents, even ones containing extensions.
Note that this use of the same namespace means that in certain cases RIF and RDF/XML documents cannot be distinguished simply by their namespace use. Moreover, since the rdf:RDF root element is optional in RDF/XML, in some cases it is not possible to distinguish between RIF and RDF/XML documents just by schema-validating or RDF-parsing the XML. In those cases, additional inspection of the structure is necessary. In general, systems should therefore be careful to maintain external file type information. This is typically done with either the media types ("application/rif+xml" and "application/rdf+xml") or the suggested filename extensions (".rif" and ".rdf").
In the tables below, the followng XML DOCTYPE declaration is assumed, allowing for abbreviation of the RDF and RIF namespaces:
<!DOCTYPE rif:Document [ <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <!ENTITY rif "http://www.w3.org/2007/rif#"> ]>
Also, the default XML namespace is assumed to be "http://www.w3.org/2007/rif#" and for use in Turtle, the following prefix declarations are assumed to be in effect:
@prefix rif: <http://www.w3.org/2007/rif#> @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> @prefix xs: <http://www.w3.org/2001/XMLSchema#>
Any RIF class element may have a first child of the form:
<id> <Const type="&rif;iri">id</Const> </id>
When this child is present, it is ignored for other processing and the id text is used as the IRI (URI-Reference) label for the focus_node, instead of it being left as a blank node.
As a special case, if the rif:Document element does not have an <id> child, its focus_node should be given the Web address (IRI) of the input XML document, if it has one.
After this optional <id> element, any RIF class element may contain a <meta> element. This element is processed
like other property elements, below.
Systems performing this transformation may also attempt to convert the metadata to RDF using the standard Frame-RDF correspondence [RIF RDF+OWL] , and include it in the returned triples. The conversion is not always possible, because some frame formulas are not expressible in RDF; systems which attempt this transformation and encounter such frame formulas in metadata should issue a warning. Even if the frames are converted to RDF like this, implementations must still keep the rif:meta triples intact, to support stable roundtripping.
Table 1, below, defines a portion of Tr. When a rif-xml-tree, X, matches the entry in column one, treating terms written like-this as metavariables, the result of Tr(X) is the pair <focus_node,G>, where G is the
singletonset of triples indicated by the second column.
Note that, although not shown in this table, <id> and <meta> child elements are allowed before the text in these elements. Additional elements after <id> and <meta> and before the character data may be allowed by extended schemas and must be processed as normal (extended) property elements.
Editor's Note: If Issue 101 is resolved to allow the use of class information, this table could potentially be simplified or folded into Table 2. Perhaps the type attribute could map to a rif:symbolspace property, and any character data after the last child could map to the value of a rif:text property.Note that metadata about Consts is applied to the focus_node, not to the RDF literal produced. For example an explanation comment on a Const is understood to explain why that value is used in that spot, not state general properties of that value.
|Input XML Pattern, X||Output RDF Triples, G|
focus_node rif:varname "variable-name"
focus_node rif:constIRI "value"
focus_node rif:constname "value"
focus_node rif:value "value"
focus_node rif:value "value"@langtag
focus_node rif:value "value"^^type-iri
Except as noted above, the Tr mapping for any class element is to a new focus node and a set of triples which depend on each of the children of the class element. The exact dependency is detailed in this section.
Each child of the class element being mapped (except as noted above) is a property
element. There are four kinds of property elements:
The mapping for each mode is specified in Table 2 below. The mapping depends on the identity of an RDF property, written as prop, and the mode. Table 3 specifies special-case values for prop and mode, but otherwise they are determined as follows:
|Mode||Property Element XML Pattern||RDF Triples added to Tr result|
. . . < child ordered="yes"> item-1 . . . item-n </child> . . .
focus_node prop ( id-1 . . . id-n ) triples-1 . . . triples-n where: <id-1, triples-1> = Tr(item-1)
. . . < child>item</child> . . .
focus_node prop id triples-n where: <id, triples> = Tr(
. . . < child>item_1</child> . . . <child>item_n</child> . . .
focus_node prop ( id-1 . . . id-n ) triples-1 . . . triples-n where: <id-1, triples-1> = Tr(item-1) ... <id-n, triples-n> = Tr(item-n)
|3||As found in <Atom> and <Expr> in BLD (but not Core or PRD):
. . .
focus_node rif:namedargs ( [ rif:argname "name-1"; rif:argvalue value-id-1 ] . . . [ rif:argname "name-n"; rif:argvalue value-id-n ] ) triples-1 . . . triples-n where: <value-id-1, triples-1> = Tr(value-1) . . . <value-id-n, triples-n> = Tr(value-n)
focus_node rif:slots ( [ rif:slotkey nk-1; rif:slotvalue nv-1 ] . . . [ rif:slotkey nk-n; rif:slotvalue nv-n ] ) tk-1 . . . tk-n tv-1 . . . tv-n where: <nk-1, tk-1> = Tr(key-1) . . . <nk-n, tk-n> = Tr(key-n) <nv-1, tv-1> = Tr(value-1) . . . <nv-n, tv-n> = Tr(value-n)
This table specifies exceptions to the default rules for determining the value of prop and the mode of the property element:
|Class Element (parent)||Property Element (child)||RDF Property (prop)||Mode|
Because the above mapping function Tr is not injective (one-to-one), the inverse mapping is not a function, but provides many outputs
each input. Intuitively, Tr loses information, such as the order in which property elements occurred
the RIF XML document,
so properly reconstructing a
RIF XML document requires additional information.
reverse mapping function Xtr is therefore the inverse of Tr constrained to
only produce schema-valid RIF XML documents:
XTr( focus-node, triples, XML-schema,
XML-Root-Element) → rif-xml-tree Editor's Note: Additional details will be provided
versions of this document. In particular, how perfect will roundtripping be? Exactly what information is lost? 7
This document is the product of the Rules Interchange Format (RIF) Working Group (see below) whose members deserve recognition for their time and commitment. The editor extends special thanks to Dave Reynolds
and Axel Polleresfor their insightful review comments.
The regular attendees at meetings of the Rule Interchange Format (RIF) Working Group at the time
of the publication were: Adrian Paschke (Freie Universitaet Berlin), Axel Polleres (DERI), Changhai Ke (IBM),Chris Welty (IBM), Christian de Sainte Marie (IBM), Dave Reynolds (HP), Gary Hallmark (ORACLE), Harold Boley (NRC), Hassan Aït-Kaci (IBM),Jos de Bruijn (FUB), Leora Morgenstern (IBM), Michael Kifer (Stony Brook), Mike Dean (BBN), Sandro Hawke (W3C/MIT), and Stella Mitchell (IBM).
Here is Example 8 from BLD converted via the RIF-in-RDF mapping to Turtle:
< http://www.w3.org/2007/rif# >. < http://www.w3.org/2010/rif-schema/bld/ex8 > :payload < http://sample.org >;:directives ( ). < http://sample.org >:meta [ :object [ :constName"pd" ]; :slots ( [ :slotkey [ :constIRI " http://purl.org/dc/terms/publisher "]; :slotvalue [ :constIRI " http://www.w3.org/ "] ] [ :slotkey [ :constIRI " http://purl.org/dc/terms/date "]; :slotvalue [ :constName "2008-04-04"^^< http://www.w3.org/2001/XMLSchema#date >] ] ) ]; :parts( [ :formula [ :if [ :allTrue( [ :args ( [ :varname"item" ] ); :predicate [ :constIRI "http://example.com/concepts#perishable"] ] [ :args ( [ :varname"item" ] [ :varname"deliverydate" ] [ :constIRI "John"] ); :predicate [ :constIRI "http://example.com/concepts#delivered"] ] [ :args ( [ :varname"item" ] [ :varname"scheduledate" ] ); :predicate [ :constIRI "http://example.com/concepts#scheduled"] ] [ :left [ :varname"diffduration" ]; :right [ :content[ :args ( [ :varname"deliverydate" ] [ :varname"scheduledate" ] ); :function [ :constIRI " http://www.w3.org/2007/rif-builtin-function#subtract-dateTimes "] ] ] ] [ :left [ :varname"diffdays" ]; :right [ :content[ :args ( [:varname"diffduration" ] ); :function[ :constIRI " http://www.w3.org/2007/rif-builtin-function#days-from-duration "] ] ] ] [ :content [ :args ( [ :varname "diffdays" ] [ :constName10 ] ); :predicate[ :constIRI " http://www.w3.org/2007/rif-builtin-predicate#numeric-greater-than "] ] ] ) ]; :then [ :args ( [ :constIRI "John"] [ :varname"item" ] ); :predicate [ :constIRI "http://example.com/concepts#reject"] ] ]; :univars( [ :varname"item" ] [ :varname"deliverydate" ] [ :varname"scheduledate" ] [ :varname"diffduration" ] [ :varname"diffdays" ] ) ] [ :formula [ :if [ :args ( [ :varname"item" ] ); :predicate [ :constIRI "http://example.com/concepts#unsolicited"] ]; :then [ :args( [ :constIRI "Fred"] [ :varname"item" ] ); :predicate [ :constIRI "http://example.com/concepts#reject"] ] ]; :univars( [ :varname"item" ] ) ] ) .