<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="xmlspec.xsl"?>
<!DOCTYPE spec PUBLIC "-//W3C//DTD Specification V2.1//EN" "http://www.w3.org/2002/xmlspec/dtd/2.10/xmlspec.dtd" [
<!ENTITY version "1.0">
<!ENTITY ne "≠">
<!ENTITY ouml "ö">
<!ENTITY times "×">
<!ENTITY order "£">
<!ENTITY le "≤">
<!ENTITY cellback "#d0d9fa">
<!ENTITY eacute "é">
<!ENTITY copy "©">
<!ENTITY sect "§">
<!ENTITY mdash "&#8212;">
<!ENTITY nbsp "&#160;">
]>
<spec w3c-doctype="wd">
  <header>
    <title>RIF Simple RDF Mapping</title>
    <w3c-designation>Internal Working Draft</w3c-designation>
    <w3c-doctype>Editor's Draft 12 July 2010</w3c-doctype>
    <!-- notice>Notice this!!</notice -->
    <publoc>
      $Id: Overview.xml,v 1.5 2010/07/13 15:40:39 eric Exp $
    </publoc>
    <prevlocs>
      <loc href="http://www.w3.org/2001/sw/rdb2rdf/rifSimpleMapping/">http://www.w3.org/2001/sw/rdb2rdf/rifSimpleMapping/</loc>
    </prevlocs>
    <latestloc>
      <loc href="http://www.w3.org/2001/sw/rdb2rdf/rifSimpleMapping/">http://www.w3.org/2001/sw/rdb2rdf/rifSimpleMapping/</loc>
    </latestloc>
    <authlist>
      <author>
	<name>Eric Prud'hommeaux</name>
	<affiliation>W3C</affiliation>
	<email href="mailto:eric@w3.org">eric@w3.org</email>
	<role>Editor</role>
      </author>
      <author>
	<name>Sandro Hawk</name>
	<affiliation>W3C</affiliation>
	<email href="mailto:sandro@w3.org">sandro@w3.org</email>
	<role>Editor</role>
      </author>
    </authlist>
    <abstract>
      <p>
A subset of RIF can be used to define mappings from constrained graphs to popular patterns.
Graphs may be constrained by being a direct expression of a relational database, or data whose schema has evolved.
The fragment of RIF described in this document meets many such cases.
      </p>
    </abstract>
    <status>
      <p>
	<em>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 <a href="http://www.w3.org/TR/">W3C technical reports index</a> at http://www.w3.org/TR/.</em>
      </p>
      <p>This is a <a href="http://www.w3.org/2005/10/Process-20051014/tr.html#RecsWD">Editors' Working Draft</a>.</p>
      <p>The documents produced by this Working Group are:</p>
      <ul>
	<li>RDB2RDF Mapping Language (R2RML) Specification</li>
	<li>RDB2RDF Mapping Language (R2RML) Conformance Tests</li>
      </ul>
      <p>This document was produced by a group operating under the <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent Policy</a>. W3C maintains a <a rel="disclosure" href="http://www.w3.org/2004/01/pp-impl/35463/status">public list of any patent disclosures</a> 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 <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential Claim(s)</a> must disclose the information in accordance with <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the W3C Patent Policy</a>.</p>
    </status>
    <languages>
      <language>en</language>
    </languages>
    <revisiondesc>
      <p>
	<emph>Last Modified: $Id: Overview.xml,v 1.5 2010/07/13 15:40:39 eric Exp $</emph>
      </p>
    </revisiondesc>
  </header>
  <body>
    <div1 id="intro">
      <head>Introduction</head>
      <p>
Custodians of data are often pushed towards materialization or replications when trying to evolve a data <em>and</em> maintain backward compatibility.
Likewise, the creation of Semantic Web views of data, be it a filesystem or a relational database, can create a view different from one that would best serve the community.
A light-weight system for defining mappings permits the creation of SemWeb-friendly views, either materialized or virtual.
This document defines a subset of RIF capable of mapping transforming <bibref ref="directG"/>s to graph forms which use common schemas like FOAF or DCIM.
      </p>
    </div1>
    <div1 id="social-simple">
      <head>Social Data Example (Informative)</head>
      <p>
Given an graph with people's names and addresses, we with to create a graph which uses the popular vocabularies FOAF and DCIM.
This done by creating rule patterns in the existing graph and creating patterns in the desired graph.
      </p>
      <!-- div style="float:right;">
      <pre style="float:left;">
	left
      </pre>
      <pre>
	right
      </pre>
      </div -->
      <div style="border: 1px solid #66ccff; ">
	<p role="caption">Constrained graph:</p>
	<pre>
@prefix xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt; .

<!-- &lt;http://foo.example/DB/People/ID.7#_&gt; &lt;http://foo.example/DB/People#ID&gt; 7 . -->&lt;http://foo.example/DB/People/ID.7#_&gt; &lt;http://foo.example/DB/People#fname&gt; "Bob"^^xsd:string .
&lt;http://foo.example/DB/People/ID.7#_&gt; &lt;http://foo.example/DB/People#addr&gt; &lt;http://foo.example/DB/Addresses/ID.18#_&gt; .
<!-- &lt;http://foo.example/DB/People/ID.8#_&gt; &lt;http://foo.example/DB/People#ID&gt; 8 . -->&lt;http://foo.example/DB/People/ID.8#_&gt; &lt;http://foo.example/DB/People#fname&gt; "Sue"^^xsd:string .

<!-- &lt;http://foo.example/DB/Addresses/ID.18#_&gt; &lt;http://foo.example/DB/Addresses#ID&gt; 18 . -->&lt;http://foo.example/DB/Addresses/ID.18#_&gt; &lt;http://foo.example/DB/Addresses#city&gt; "Cambridge"^^xsd:string .
&lt;http://foo.example/DB/Addresses/ID.18#_&gt; &lt;http://foo.example/DB/Addresses#state&gt; "MA"^^xsd:string .
	</pre>
      </div>
      <p>The following RIF rules (expressed here in RIF presentation syntax) define a view of the in using the vcard vocabulary:</p>
      <div style="border: 1px solid #66ccff; ">
	<p role="caption">RIF mapping:</p>
      <pre>
Document(
  Prefix(vcard    &lt;http://www.w3.org/2006/vcard/ns#&gt;)
  Prefix(db_pers  &lt;http://foo.example/DB/People#&gt;)
  Prefix(db_addr  &lt;http://foo.example/DB/Addresses#&gt;)

  Group (
    Forall ?Person ?Name (
        ?Person[vcard:fn-&gt;?Name] :- ?Person[db_pers:name-&gt;?Name]
    )
    Forall ?Person ?Addr (
	?Person[vcard:adr-&gt;?Addr] :- ?Person[db_pers:addr-&gt;?Addr]
    )
    Forall ?Addr ?City (
	?Addr[vcard:locality-&gt;?City] :- ?Addr[db_addr:city-&gt;?City]
    )
    Forall ?Addr ?State (
	?Addr[vcard:region-&gt;?State] :- ?Addr[db_addr:state-&gt;?State]
    )
  )
)

      </pre>
      </div>
      <div style="border: 1px solid #66ccff; ">
	<p role="caption">Presented view:</p>
	<pre>
@prefix xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt; .

<!-- &lt;http://foo.example/DB/People/ID.7#_&gt; &lt;http://www.w3.org/2006/vcard/ns#ID&gt; 7 . -->&lt;http://foo.example/DB/People/ID.7#_&gt; &lt;http://www.w3.org/2006/vcard/ns#fn&gt; "Bob"^^xsd:string .
&lt;http://foo.example/DB/People/ID.7#_&gt; &lt;http://www.w3.org/2006/vcard/ns#adr&gt; &lt;http://foo.example/DB/Addresses/ID.18#_&gt; .
<!-- &lt;http://foo.example/DB/People/ID.8#_&gt; &lt;http://www.w3.org/2006/vcard/ns#ID&gt; 8 . -->&lt;http://foo.example/DB/People/ID.8#_&gt; &lt;http://www.w3.org/2006/vcard/ns#fn&gt; "Sue"^^xsd:string .

<!-- &lt;http://foo.example/DB/Addresses/ID.18#_&gt; &lt;http://www.w3.org/2006/vcard/ns#ID&gt; 18 . -->&lt;http://foo.example/DB/Addresses/ID.18#_&gt; &lt;http://www.w3.org/2006/vcard/ns#locality&gt; "Cambridge"^^xsd:string .
&lt;http://foo.example/DB/Addresses/ID.18#_&gt; &lt;http://www.w3.org/2006/vcard/ns#region&gt; "MA"^^xsd:string .
	</pre>
      </div>

    </div1>
    <div1 id="social-node-xform">
      <head>Node Transformation Example (Informative)</head>
      <p>
In addition to changing the graph structure, many use cases demand manipulation of nodes in the graph.
      </p>
      <!-- div style="float:right;">
      <pre style="float:left;">
	left
      </pre>
      <pre>
	right
      </pre>
      </div -->
      <div style="border: 1px solid #66ccff; ">
	<p role="caption">RIF mapping:</p>
      <pre>
Document(
  Prefix(pred &lt;http://www.w3.org/2007/rif-builtin-predicate#&gt;)

  (* this:g1
     this:g1[rdfs:comment-&gt;" 

       This ruleset is meant to illustrate the use of RIF for
       rdb2rdf.  In this example, the direct mapping produces
       identifiers like:
            http://foo.example/DB/People/ID.7
	    http://foo.example/DB/Addresses/ID.18
       but we want to convert to identifiers like
            http://bar.example/v01/instances/P6
	    http://bar.example/v01/instances/A17

     " ]
  *)
  Group (
 
    Forall ?Res1 ?Res2 ?Pre1 ?Pre2 ?S1 (
       rename_any(?Res1 ?Res2 ?Pre1 ?Pre2) :- And(
          External(pred:iri-string(?Res1 ?S1))
          External(pred:startswith(?S1 ?Pre1))
          External(pred:iri-string(?Res2 External(func:concat(?Pre2 func:substring(?S1 func:numeric-add(1 func:string-length(func:numeric-add(?Pre1))))))))
       )
    )

    Forall ?Res1 ?Res2 (
       rename(?Res1 ?Res2) :- 
          rename_any(?Pre1 ?Res2 
	             "http://foo.example/DB/People/ID."
	             "http://bar.example/v01/instances/P")
       rename(?Res1 ?Res2) :- 
          rename_any(?Pre1 ?Res2 
	             "http://foo.example/DB/Addresses/ID."
	             "http://bar.example/v01/instances/A")
    )

    (* :main_rule
       :main_rule[rdfs:comment-&gt;
         "Every triple using the old URI (in the subject or
          object position) implies a corresponding triple using
          the new URI."]
    *)
    Forall ?X1 ?X2 ?P ?B (
        ?X1[?P-&gt;?B] :- And( ?X0[?P-&gt;?B] rename(?X0 ?X1) )
        ?B[?P-&gt;?X1] :- And( ?B[?P-&gt;?X0] rename(?X0 ?X1) )



    )
  )
)
      </pre>
      </div>
      <div style="border: 1px solid #66ccff; ">
	<p role="caption">Presented view:</p>
	<pre>
@prefix xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt; .

<!-- &lt;http://bar.example/v01/instances/P.7#_&gt; &lt;http://www.w3.org/2006/vcard/ns#ID&gt; 7 . -->&lt;http://bar.example/v01/instances/P.7#_&gt; &lt;http://www.w3.org/2006/vcard/ns#fn&gt; "Bob"^^xsd:string .
&lt;http://bar.example/v01/instances/P.7#_&gt; &lt;http://www.w3.org/2006/vcard/ns#adr&gt; &lt;http://bar.example/v01/instances/A.18#_&gt; .
<!-- &lt;http://bar.example/v01/instances/P.8#_&gt; &lt;http://www.w3.org/2006/vcard/ns#ID&gt; 8 . -->&lt;http://bar.example/v01/instances/P.8#_&gt; &lt;http://www.w3.org/2006/vcard/ns#fn&gt; "Sue"^^xsd:string .

<!-- &lt;http://bar.example/v01/instances/A.18#_&gt; &lt;http://www.w3.org/2006/vcard/ns#ID&gt; 18 . -->&lt;http://bar.example/v01/instances/A.18#_&gt; &lt;http://www.w3.org/2006/vcard/ns#locality&gt; "Cambridge"^^xsd:string .
&lt;http://bar.example/v01/instances/A.18#_&gt; &lt;http://www.w3.org/2006/vcard/ns#region&gt; "MA"^^xsd:string .
	</pre>
      </div>

    </div1>
    <div1 id="refs">
      <head>References</head>
    </div1>
  </body>
  <back>
    <blist>
      <bibl id="SPARQL" href="http://www.w3.org/TR/rdf-sparql-query/">SPARQL Query Language for RDF, Eric Prud'hommeaux and Andy Seaborne 2008.</bibl>
      <bibl id="SQL" href="http://en.wikipedia.org/wiki/SQL">SQL.<ednote><edtext>need a better reference here</edtext></ednote></bibl>
      <bibl id="RDF" href="http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/">Resource Description Framework (RDF): Concepts and Abstract Syntax, G. Klyne, J. J. Carroll,  Editors, W3C Recommendation, 10 February 2004</bibl>
      <bibl id="ReuseableIDs" href="http://esw.w3.org/topic/Rdb2RdfXG/ReusableIdentifier">Reusable Identifiers in the RDB2RDF mapping language, Michael Hausenblas and Themis Palpanas, 2009.</bibl>
      <bibl id="URI" href="http://tools.ietf.org/html/rfc3986">RFC3986 - Uniform Resource Identifier (URI): Generic Syntax</bibl>
    </blist>
    <div1 id="sec-cvsLog">
      <head>CVS History</head>
      <div2 id="sec-cvsLog-meat">
	<pre>
$Log: Overview.xml,v $
Revision 1.5  2010/07/13 15:40:39  eric
+ social-node-xform

Revision 1.4  2010/07/13 15:35:04  eric
+ presented view

Revision 1.3  2010/07/13 15:26:35  eric
+ example

Revision 1.2  2010/07/13 00:10:45  eric
+ abstract and introduction

Revision 1.1  2010/07/12 23:35:20  eric
CREATED

Revision 1.10  2010/07/12 23:15:42  eric
~ typos revealed when geeking with Sandro

Revision 1.9  2010/06/15 15:23:43  eric
~ validating

Revision 1.8  2010/06/15 14:33:59  eric
~ s/Heading/Header/ per <a href="http://www.googlefight.com/index.php?lang=en_GB&amp;word1=relational+heading&amp;word2=relational+header">google fight</a>

Revision 1.7  2010/06/15 14:27:08  eric
~ s/∀/∣/g per cygri's comment

Revision 1.6  2010/06/07 15:49:34  eric
+ <a href="#extend">Extending the Direct Mapping</a> section

Revision 1.5  2010/06/07 14:35:18  eric
+ finished mappings

Revision 1.4  2010/06/03 23:02:58  eric
~ SNAPSHOT

Revision 1.3  2010/06/03 13:06:00  eric
+ start on literal map

Revision 1.2  2010/06/03 12:43:30  eric
~ made algebra all symboly

Revision 1.1  2010/06/02 15:03:34  eric
CREATED

	</pre>
      </div2>
    </div1>
  </back>
</spec>
       
