<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Relational Database to RDF Mapping Patterns</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Juan Sequeda</string-name>
          <email>jsequeda@cs.utexas.edu</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Freddy Priyatna</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Boris Villazon-Terrazas</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Computer Science, The University of Texas at Austin</institution>
          ,
          <country country="US">USA</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>OEG-DIA, FI, Universidad Politecnica de Madrid</institution>
          ,
          <country country="ES">Spain</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>In order to integrate relational databases into Semantic Web applications, relational databases need to be mapped to RDF. The W3C RDB2RDF Working Group is in the process of ratifying two standards to map relational databases to RDF: Direct Mapping and R2RML mapping language. Through our experience as implementors of two RDB2RDF systems: Ultrawrap and Morph, and as authors of R2RML mappings, we have observed mappings that are reusable in order to solve a commonly occurring problem. In this paper, we have compiled these mappings and present a non-exhaustive list of RDB2RDF Mapping Patterns. We aspire that the mapping patterns in this paper are considered as a starting point for new mapping patterns.</p>
      </abstract>
      <kwd-group>
        <kwd>RDB2RDF</kwd>
        <kwd>Mapping Patterns</kwd>
        <kwd>Mapping Language</kwd>
        <kwd>R2RML</kwd>
        <kwd>Relational Databases</kwd>
        <kwd>SPARQL</kwd>
        <kwd>SQL</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>Assuming the RDB2RDF standards are widely adopted, we expect the mapping
patterns to increase. We aspire that the mapping patterns in this paper are
considered as a starting point for new mapping patterns.
2</p>
    </sec>
    <sec id="sec-2">
      <title>A Motivating Example</title>
      <p>
        We present an example that motivates the need of RDB2RDF mapping patterns.
Due to lack of space, we do not present an overview of R2RML. We refer the
reader to the R2RML spec [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. Assume you have a table Student with attributes
id, name, and homephone. An application would like to map the table person
to foaf:Person, create URIs based on the attribute id, map the attribute name
to foaf:name and homephone to foaf:phone. The following R2RML mapping will
produce the desired output:
&lt;Trrrrrrriprr:::lrrsppeurr::sbeeooMddjbbeaiijjccceeptaaccSMtttttMMeeuaOOpaadbbppejjn[eet[[cc&gt;rrrttrrrMMa:::aacctppooerllmruu[[:pmmTlnnrrarrrtipe""::lnhppea"orrsmmheeMeddteatp"iippcch]aa:;o;/ttn/eeer re"xff:]aoo;l omaagff]pi::lcnpe.aah.mlcoTonemae;/b; rlee s o[ u rrcr e: /taSbtluedNeanmt /ef id" sgt"u;de] n;t " ] ;
      </p>
      <p>We observe a One to One mapping between tables and ontology classes and
a One to One mapping between attributes and ontology properties.</p>
      <p>Now assume that the table Student has a new attribute, mobilephone, which
we would also like to map to foaf:phone. This means that we would need to
have a Many to One mapping between attributes and an ontology property. The
previous mapping could be augmented by adding rr:objectMap [rr:column
"mobilephone"]; to the existing rr:predicateObjectMap that has foaf:phone as a
predicate. Another solution would be to repeat the entire rr:predicateObjectMap, but
with a rr:column of mobilephone. This type of pattern impacts query
performance. The following SPARQL query: SELECT ?s ?o WHERE f?s foaf:phone
?og would get translated to the following SQL query: SELECT id, homephone
FROM Student UNION SELECT id, mobilephone FROM Student. If we were to
increase the amount of attributes mapped to the same ontology property, the
size of the SQL query would increase. This example suggests that there is a
tradeo between mapping patterns and query performance. In order to further
study tradeo s and design decisions of RDB2RDF mappings, it is important
to understand the di erent types of mapping patterns. In the next section, we
present fourteen mapping patterns which we have observed as implementors of
RDB2RDF systems and authors of R2RML mappings.
3</p>
    </sec>
    <sec id="sec-3">
      <title>R2RML Mapping Patterns</title>
      <p>A RDB2RDF mapping pattern is a reusable mapping that solves a commonly
occurring problem. We present four type of mapping patterns: Attribute Mapping
Patterns, Table Mapping Patterns, Join Mapping Patterns and Value
Translation Patterns. Each pattern consists of a name, a question that de nes the
problem that is being addressed, description of the context, description of the
solution in R2RML, an example R2RML mapping, a discussion and related
patterns. Some mapping patterns may consist of di erent R2RML solutions.
3.1</p>
      <sec id="sec-3-1">
        <title>Pattern 1: One to One Table Mapping</title>
        <sec id="sec-3-1-1">
          <title>How to map a table to an ontology class?</title>
          <p>Context: An application would like to map a tables to an ontology class.
Moreover, every record of the tables is mapped to an instance of the corresponding
ontology classes. For example, the table student is mapped to foaf:Person.
Solution: Create a TriplesMap for the table and specify the rr:logicalTable
whose value corresponds to the table name. In the TriplesMap, create a rr:subjectMap
with a rr:template to de ne the URI template for each row. Finally, the rr:subjectMap
will have a rr:class corresponding to the ontology class for that table.</p>
        </sec>
      </sec>
      <sec id="sec-3-2">
        <title>Example R2RML Mapping</title>
        <p>&lt;TriplesMapStudent&gt; a r r : TriplesMap ; r r : l o g i c a l T a b l e [ r r : tableName " student " ] ;
r r : subjectMap [ r r : c l a s s f o a f : Person ;
r r : template " http : // example . com/ r e s o u r c e / Student /f s i d g" ] .</p>
        <p>Discussion: This is the simplest pattern for table mapping. This is the case of
the Direct Mapping, which automatically generates a unique ontology class for
each table. However, a user has the option to specify a particular ontology class.</p>
      </sec>
      <sec id="sec-3-3">
        <title>Related Patterns: N/A</title>
      </sec>
      <sec id="sec-3-4">
        <title>Pattern 2: One to Many Table Mapping</title>
        <sec id="sec-3-4-1">
          <title>How to map a table to several ontology classes?</title>
          <p>Context: An application would like to map a table to many ontology classes.
Moreover, every record of the table is mapped to an instance of the corresponding
ontology classes. For example, the table student is mapped to foaf:Person and
ex:Student.</p>
          <p>Solution: Create a TriplesMap for the table and specify the rr:logicalTable
whose value corresponds to the table name. In the TriplesMap, create a rr:subjectMap
with a rr:template to de ne the URI template for each row. Finally, the rr:subjectMap
will have multiple rr:class that correspond to the ontology classes for that table.</p>
        </sec>
      </sec>
      <sec id="sec-3-5">
        <title>Example R2RML Mapping</title>
        <p>&lt;TriplesMapStudent&gt; a r r : TriplesMap ; r r : l o g i c a l T a b l e [ r r : tableName " student " ] ;
r r : subjectMap [ r r : template
" http :/ / example . com/ r e s o u r c e / Student /f s i d g";
r r : c l a s s f o a f : Person ; r r : c l a s s ex : Student ] .</p>
        <p>Discussion: This pattern extends Pattern 1 by adding multiple rr:class.</p>
      </sec>
      <sec id="sec-3-6">
        <title>Related Patterns: Pattern 1</title>
        <p>3Except for the case when the table represents a many-to-many relationship</p>
      </sec>
      <sec id="sec-3-7">
        <title>Pattern 3: Many to One Table Mapping</title>
        <sec id="sec-3-7-1">
          <title>How to map several tables to an ontology class?</title>
          <p>Context: An application would like to map many tables to an ontology class.
Moreover, every record of these table are mapped to an instance of the
corresponding ontology class. For example, the tables student and professor are both
mapped to foaf:Person.</p>
          <p>Solution: Repeat the solution in pattern 1 for each table to be mapped.
Example R2RML Mapping
&lt;TriplesMapStudent&gt; a r r : TriplesMap ; r r : l o g i c a l T a b l e [ r r : tableName " student " ] ;
r r : subjectMap [ r r : c l a s s f o a f : Person ;</p>
          <p>r r : template " http : / / example . com/ r e s o u r c e / Student /f s i d g" ] .
&lt;TriplesMapStudent&gt; a r r : TriplesMap ; r r : l o g i c a l T a b l e [ r r : tableName " p r o f e s s o r " ] ;
r r : subjectMap [ r r : c l a s s f o a f : Person ;</p>
          <p>r r : template " http : / / example . com/ r e s o u r c e / P r o f e s s o r /f s i d g" ] .</p>
          <p>Discussion: This pattern extends Pattern 1 and it is used when instances of an
ontology class may be distributed over several tables.</p>
        </sec>
      </sec>
      <sec id="sec-3-8">
        <title>Related Patterns: Pattern 1</title>
      </sec>
      <sec id="sec-3-9">
        <title>Pattern 4: Many to Many Table Mapping</title>
        <sec id="sec-3-9-1">
          <title>How to map several tables to several ontology classes?</title>
          <p>Context: An application would like to map a table to several ontology classes.
Additionally, the application would like to map an ontology class to several
tables.</p>
          <p>Solution: Repeat solution of pattern 2 for each table to be mapped.</p>
        </sec>
      </sec>
      <sec id="sec-3-10">
        <title>Example R2RML Mapping</title>
        <p>&lt;Trrrip: lseusbMjeacptSMtuapden[ t&gt;rr rr a:: tcerl mars:psTlartfipoelae"fsh:MPtateppr s:;/on/r re; x: arlomrg:piclcelaa.lcsTosma/bexrlee: sAo[cuardrcreem:/tiacSbtlu]edNe.anmt /ef s "idstgu"d; ent " ] ;
&lt;Trrrip: lseusbMjeacptPMraopf&gt;[ a rr rrr r:: t:ceTlmarsippsllaetfsoeMaa"fph:Pt;teprrrs:/o:n/l oe; xg aircmra:plclTel aa. cbsoslme /exr[ e: sArorcu:atrdacebeml/eicPNra]omf e.e s s o"rp/rfosf ieds sgo"r; " ] ;
Discussion: This pattern extends Pattern 3. In addition to instances of an
ontology classes are distributed over several database tables, each row of the
database table produces multiple ontology instances.</p>
        <p>Related Patterns: Pattern 2, Pattern 3
3.2</p>
      </sec>
      <sec id="sec-3-11">
        <title>Attribute Mapping Patterns</title>
        <p>Attributes of tables are mapped to ontology properties. In R2RML, a TripleMap
can have zero or more rr:predicteObjectMap, which in turn speci es a
predicateobject pair. The following patterns de ne di erent ways that an attribute can
be mapped to an ontology property.</p>
      </sec>
      <sec id="sec-3-12">
        <title>Pattern 5: One to One Attribute Mapping</title>
        <sec id="sec-3-12-1">
          <title>How to map an attribute to an ontology property?</title>
          <p>Context: An application would like to map an attribute to an ontology property.
For example, the attribute rstname is mapped to foaf:givenName.
Solution: Given a TripleMap, create a rr:predicateObjectMap for the attribute,
which has only one rr:predicate for the ontology property and a rr:objectMap
for the attribute.</p>
        </sec>
      </sec>
      <sec id="sec-3-13">
        <title>Example R2RML Mapping</title>
        <p>&lt;TriplesMapStudent&gt; a r r : TriplesMap ; r r : l o g i c a l T a b l e [ r r : tableName " student " ] ;
rr rr rr:: rrspur::beotdejbemijcceptacMlttaMeatOpaebpj"[eh[crtttrMp:ac:/pol/ue[mxnar mr":pfplierr.escdtonimcaa/mtreee s"of]uo; arcf] e: /g.iSvteundNeanmt /ef; s i d g"; ] ;
Discussion: This is the simplest pattern for attribute mapping. This is the
case of the Direct Mapping, which automatically generates a unique ontology
property for each attribute.</p>
      </sec>
      <sec id="sec-3-14">
        <title>Related Patterns: N/A</title>
      </sec>
      <sec id="sec-3-15">
        <title>Pattern 6: One to Many Attribute Mapping</title>
        <sec id="sec-3-15-1">
          <title>How to map an attribute to several ontology properties?</title>
          <p>Context: An application would like to map an attribute to several ontology
properties. For example, the attribute lastname is mapped to foaf:familyName
and ex:apellido.</p>
          <p>Solution 1: Given a TripleMap, create a rr:predicateObjectMap for the
attribute, which has a rr:predicate for each ontology property and a rr:objectMap
for the attribute.</p>
        </sec>
      </sec>
      <sec id="sec-3-16">
        <title>Example R2RML Mapping for Solution 1</title>
        <p>&lt;Trrrrripr::lrspeur:sbeoMdjbeaijcceptacSMtttMeuaOpadbpejn[et[c&gt;rrtrrMa::actpoerlmru[:pmTlnrarrtipe":llpea"rssheMtdtnatiappcma:;/et/er"re]x;f: aol oma]gfpi:lcfeaa.mlcToimlay/bNrlaeems oe[u; rrcrrer: /t:aSpbtrlueeddNeiacnmat /teef s "eidxstg:ua"dp;een]lt;l i"d o] ;;
Solution 2: Repeat the solution for Pattern 5 for the attribute to be mapped
but having the rr:predicate speci c to each ontology property</p>
      </sec>
      <sec id="sec-3-17">
        <title>Example R2RML Mapping for Solution 2</title>
        <p>&lt;Trrrrrrriprr:::lrrsppeurr::sbeeppMddjrreaiieecccpddtaaSMiittccteeuaaaOOpdttbbeeejjn[eetefcc&gt;xorttra:MMaf:aaat:pppefreamrlm[[l:piTildlayrotiNpe;alem"rsrehM;:tatoppbrrj:;e/:c/ortbreMxj:eaalcpomtgMpi[lcaerapr.lc:Toc[moarl/rbur:lmeceonslo[uu"mlrrancrse:t"/tnaSlaabtmsluetedNne"aan]mmt; e/ef"].s] "i;dstg]u;"d; en] t; " ] ;
Discussion: Solution 1 is a short cut for Solution 2.</p>
      </sec>
      <sec id="sec-3-18">
        <title>Related Patterns: Pattern 5</title>
      </sec>
      <sec id="sec-3-19">
        <title>Pattern 7: Many to One Attribute Mapping</title>
        <sec id="sec-3-19-1">
          <title>How to map several attributes to an ontology property?</title>
          <p>Context: An application would like to map several attributes to an ontology
property. For example, the attribute homephone and mobilephone is mapped to
foaf:phone.</p>
          <p>Solution 1: Given a TripleMap, create a rr:predicateObjectMap, which has only
a rr:predicate for the ontological property and a rr:objectMap for each attribute.</p>
        </sec>
      </sec>
      <sec id="sec-3-20">
        <title>Example R2RML Mapping for Solution 1</title>
        <p>&lt;TriplesMapStudent&gt; a r r : TriplesMap ; r r : l o g i c a l T a b l e [ r r : tableName " student " ] ;
r r : subjectMap [ r r : template " http : / / example . com/ r e s o u r c e / Student /f s i d g"; ] ;
r r : predicateObjectMap [ r r : p r e d i c a t e f o a f : phone ;</p>
        <p>r r : objectMap [ r r : column "homephone " ] ; r r : objectMap [ r r : column " mobilephone " ] ; ] .
Solution 2: Repeat the solution for Pattern 5 for each attribute to be mapped
Example R2RML Mapping for Solution 2
&lt;TriplesMapStudent&gt; a r r : TriplesMap ; r r : l o g i c a l T a b l e [ r r : tableName " student " ] ;
r r : subjectMap [ r r : template " http : / / example . com/ r e s o u r c e / Student /f s i d g"; ] ;
r r : predicateObjectMap [ r r : p r e d i c a t e f o a f : phone ;</p>
        <p>r r : objectMap [ r r : column "homephone " ] ; ] ;
r r : predicateObjectMap [ r r : p r e d i c a t e f o a f : phone ;</p>
        <p>r r : objectMap [ r r : column " mobilephone " ] ; ] .</p>
        <p>Discussion: Solution 1 is a short cut for Solution 2. As described in the
motivating example of Section 2, this pattern impacts performance on queries that
select on the ontology property.</p>
      </sec>
      <sec id="sec-3-21">
        <title>Related Patterns: Pattern 5</title>
      </sec>
      <sec id="sec-3-22">
        <title>Pattern 8: Many to Many Attribute Mapping</title>
        <sec id="sec-3-22-1">
          <title>How to map several attributes to several ontology properties?</title>
          <p>Context: An application would like to map an attribute to several ontology
predicates. Additionally, the application would like to map an ontology predicate
to several attributes.</p>
          <p>Solution 1: Combine Solution 1 of Pattern 6 with Solution 1 of Pattern 7.</p>
        </sec>
      </sec>
      <sec id="sec-3-23">
        <title>Example R2RML Mapping for Solution 1</title>
        <p>&lt;TriplesMapStudent&gt; a r r : TriplesMap ; r r : l o g i c a l T a b l e [ r r : tableName " student " ] ;
r r : subjectMap [ r r : template " http : / / example . com/ r e s o u r c e / Student /f s i d g"; ] ;
r r : predicateObjectMap [ r r : p r e d i c a t e f o a f : phone ; r r : p r e d i c a t e ex : t e l e f o n o ;
r r : objectMap [ r r : column "homephone " ] ; r r : objectMap [ r r : column " mobilephone " ] ; ] .
Solution 2: Combine Solution 2 of Pattern 6 with Solution 2 of Pattern 7.
Example R2RML Mapping for Solution 2
the result to an ontology property. For example, concatenate the attributes
rstname and lastname and map it to foaf:name.</p>
        <p>Solution 1: Given a TripleMap, create a rr:predicateObjectMap which has a
rr:predicate for the ontology property and the rr:objectMap as a rr:template.
The concatenation is represented as a template.</p>
      </sec>
      <sec id="sec-3-24">
        <title>Example R2RML Mapping for Solution 1</title>
        <p>&lt;TriplesMapStudent1&gt; a r r : TriplesMap ; r r : l o g i c a l T a b l e [ r r : tableName " student " ] ;
r r : subjectMap [ r r : template " http :/ / example . com/ r e s o u r c e / Student /f s i d g" ] ;
r r : predicateObjectMap [</p>
        <p>r r : p r e d i c a t e f o a f : name ; r r : objectMap [ r r : template "f f i r s t n a m e g f lastname g" ] ; ] .
Solution 2: Create a new TripleMap with an R2RML view which consists of
a rr:logicalTable that has a rr:sqlQuery which includes the concatenation.
Additionally, create a rr:predicateObjectMap which has a rr:predicate for the
ontology property and the rr:objectMap for the attribute which represents the
concatenation in the SQL query.</p>
      </sec>
      <sec id="sec-3-25">
        <title>Example R2RML Mapping for Solution 2</title>
        <p>Discussion: Consider the SPARQL query SELECT ?s ?fullname WHERE f?s
foaf:name ?fullname g. Solution 1 would produce a SQL query and concat
the name in the SELECT clause. Solution 2 does the concatenation operation as
a SQL query as speci ed in rr:sqlQuery and then use this query as a subquery.
S o l u t i o n 1 SQL : SELECT sid , f i r s t n a m e j j ' ' j j lastname as fullname FROM student
S o l u t i o n 2 SQL : SELECT sid , fullname</p>
        <p>FROM (SELECT sid , f i r s t n a m e j j ' ' j j lastname AS fullname</p>
        <p>FROM student )
Note that these queries are semantically equivalent. From a query performance
perspective, they should be equal unless the RDBMS does not have optimizations
for subqueries.</p>
      </sec>
      <sec id="sec-3-26">
        <title>Related Patterns: Pattern 5 3.3</title>
      </sec>
      <sec id="sec-3-27">
        <title>Join Mapping Patterns</title>
        <p>Foreign Key relationships among tables can be mapped to ontology properties.
The following patterns de ne di erent ways that foreign key relationships can
be mapped to an ontology property.</p>
      </sec>
      <sec id="sec-3-28">
        <title>Pattern 10: Foreign Key between Two Tables</title>
        <sec id="sec-3-28-1">
          <title>How to represent the relationship between two tables?</title>
          <p>Context: An application would like to map a table to an ontology class.
However, some of the property values are stored in another table. Therefore, it is
necessary to perform a join to get those values.</p>
          <p>Solution: Given two tables, one table will be considered the child and the other
the parent. Create a TripleMap for each table. Given the child TripleMap,
create a rr:predicateObjectMap which will have, in addition to the rr:predicate,
a rr:objectMap which has a rr:parentTripleMap and a rr:joinCondition. The
rr:parentTripleMap will point to the parent TripleMap and the rr:joinCondition
will have a rr:child and rr:parent which represent the join attributes in the child
and parent table respectively.</p>
        </sec>
      </sec>
      <sec id="sec-3-29">
        <title>Example R2RML Mapping</title>
        <p>Discussion: This pattern describes an R2RML mapping that joins two tables.
This mapping can also be represented using Pattern 11. However, if a join
involves more than two tables, then Pattern 11 must be used. The addition of
another property that involves a join in Pattern 10 means that the user has
to specify a new parent TriplesMap and then refer this parent TriplesMap in a
rr:objectMap for the new property. On the other hand, the rr:logicalTable value
stays the same and no changes needed.</p>
      </sec>
      <sec id="sec-3-30">
        <title>Related Patterns: Pattern 11</title>
      </sec>
      <sec id="sec-3-31">
        <title>Pattern 11: Foreign Keys between Two or more Tables</title>
        <sec id="sec-3-31-1">
          <title>How to represent the relationship between two or more tables?</title>
          <p>Context: An application would like to map a table to an ontology class.
However, some of the property values are stored in other tables. Therefore, it is
necessary to perform a joins to get those values.</p>
          <p>Solution: Create a TripleMap with an R2RML view which consists of a rr:logicalTable
that has a rr:sqlQuery which includes a SQL query that represent explictly the
join(s).</p>
        </sec>
      </sec>
      <sec id="sec-3-32">
        <title>Example R2RML Mapping</title>
        <p>&lt;TriplesMapStudent&gt; a r r : TriplesMap ; r r : l o g i c a l T a b l e [ r r : sqlQuery """
rr rrWSr::ErspHLuEr:EbeRoCdjbEeTijccestacs.Mttc.MeasoOpaiubdpnj[etA[crSrtyrrMrs:oait:fdpetmeb,m[iprcpltra.lhrcateot:=eup"nr"chethdtr.tyctiptcopca:u/ot:n//det/eerxeeyAxxamaSi:dmcpocpleuo"leun."o.nt"rrot]gyrr;gO/y/rfceBroseidosroutehurFcr;RecOe/M/SCtusotduuendntetryn/f/tfs sicdi,dgcg"o";u; n];t] r;y ] c .
Discussion: If the join is between two tables, then Pattern 10 can be used.
However, if the join is between more than two tables, then Pattern 10 can not
be used and the SQL query must be made explicit. Unlike Pattern 10, Pattern
11 does not require to have additional TriplesMap needed in order to map the
property that needs a join. An addition of a new property that involves a join
does not require to create additional TriplesMap instance, but the user has to
modify the SQL query.</p>
      </sec>
      <sec id="sec-3-33">
        <title>Related Patterns: Pattern 10</title>
      </sec>
      <sec id="sec-3-34">
        <title>Pattern 12: Many to Many Table</title>
        <sec id="sec-3-34-1">
          <title>How to map a table that represents a many-to-many relationship between two other tables to an ontology property?</title>
          <p>Context: A many-to-many table represents a relationship between two entities.
For example, the table StudentSport records the relationship of which Students
play a speci c Sport. Several students can play a sport and several sports can be
played by a student. An application would like to map the many-to-many table
to an ontology property.</p>
          <p>Solution: Create a TriplesMap for the many-to-many table. Specify the rr:logicalTable
whose value corresponds to the table name of the many-to many table. In the
TriplesMap, create a rr:subjectMap with a rr:template to de ne the URI
template for one of the tables of the many-to-many relationship. Create an instance
of rr:predicateObjectMap which has a rr:predicate for the ontology property.
Finally, create a rr:objectMap with a rr:template to de ne the URI template for
the other table of the many-to-many relationship.</p>
        </sec>
      </sec>
      <sec id="sec-3-35">
        <title>Example R2RML Mapping</title>
        <p>&lt;TriplesMapStudentSport&gt; a r r : TriplesMap ;
r r : l o g i c a l T a b l e [ r r : tableName " StudentSport " ] ;
rr rr :: spurbedjeicctaMteaOpbj[ecrtrM:atpem[plrarte: p"rhe dttipc a:/t/e exexa m:ppllaey. sor; g / r e s o u r c e / Student /f studentid g"; ] ;
r r : objectMap [ r r : template " http :// example . org / r e s o u r c e / Sport /f s p o r t i d g" ] ; ] .
Discussion: This mapping can also be represented through Pattern 11 given
that it consists of a join between three tables (Student, StudentSport and Sport).</p>
      </sec>
      <sec id="sec-3-36">
        <title>Related Patterns: Pattern 11 3.4</title>
      </sec>
      <sec id="sec-3-37">
        <title>Value Translation Patterns</title>
        <p>It is common that speci c values in the database are code values which need to be
translated to URIs. R2RML relies on SQL's CASE statement for the translation.
The following patterns de ne di erent ways that values can be translated.</p>
      </sec>
      <sec id="sec-3-38">
        <title>Pattern 13: Translate Values</title>
        <sec id="sec-3-38-1">
          <title>How to map values in a table to URIs?</title>
          <p>Context: An application would like to map values in the data to IRIs. For
example, if the value in a job attribute is engineer, then a special IRI needs to
be generated. A translation using rr:template is not possible because templates
can only use the same values from the database.</p>
          <p>Solution: Create a new TripleMap with an R2RML view which consists of a
rr:logicalTable that has a rr:sqlQuery. Represents the translation in the SQL
query by using SQL CASE statement.</p>
        </sec>
      </sec>
      <sec id="sec-3-39">
        <title>Example R2RML Mapping</title>
        <p>&lt;#TriplesMap1&gt; a r r : TriplesMap ; r r : l o g i c a l T a b l e [ r r : sqlQuery """</p>
        <p>SELECT EMP. , (CASE JOB</p>
        <p>WHEN 'CLERK' THEN ' general o f f i c e ' WHEN 'NIGHTGUARD' THEN ' s e c u r i t y '</p>
        <p>WHEN 'ENGINEER' THEN ' engineering ' END) ROLE FROM EMP """ ] ;
rr rr :: spurbedjeicctaMteaOpbj[ecrtrM:atpem[plrarte: p"rhe dttipc a:/t/e deaxta: .r eoxl ea m;ple . com/ employee /fEMPNOg"; ] ;
r r : objectMap [ r r : template " http :// data . example . com/ r o l e s /fROLEg";</p>
        <p>r r : termType r r : IRI ; ] ; ] .</p>
        <p>Discussion: The R2RML language does not have the expressivity to represent
such value translation. Therefore, translating values has been pushed into SQL
using the CASE statement. Query performance depends on the optimizations
that a RDBMS has for the CASE statement.</p>
      </sec>
      <sec id="sec-3-40">
        <title>Related Patterns: N/A</title>
      </sec>
      <sec id="sec-3-41">
        <title>Pattern 14: Translate Values between Tables</title>
        <sec id="sec-3-41-1">
          <title>How to map values in a referenced table</title>
          <p>Context: An application would like to map a table to an ontology class. The
table has a foreign key that references another table. The referenced table contains
columns whose values need to be translated into URIs.</p>
          <p>Solution 1: Combine Pattern 11 and Pattern 13.</p>
        </sec>
      </sec>
      <sec id="sec-3-42">
        <title>Example R2RML Mapping for Solution 1</title>
        <p>&lt;TriplesMapStudent&gt; a r r : TriplesMap ; r r : l o g i c a l T a b l e [ r r : sqlQuery """
SELECT s . s i d AS sid , a . aid AS aid , (CASE a . a r t i c l e t y p e</p>
        <p>WHEN ' ppr ' THEN ' Paper ' WHEN ' ths ' THEN ' Thesis ' ) AS ArticleType</p>
        <p>FROM student s , a r t i c l e a WHERE s . s i d=a . author """ ] ;
r r : subjectMap [ r r : template " http :/ / example . com/ r e s o u r c e / Student /f s i d g"; ] ;
r r : predicateObjectMap [ r r : p r e d i c a t e ex : isAuthorOf ;</p>
        <p>r r : objectMap [ r r : template " http : // example . com/ r e s o u r c e /f ArticleType g/f aid g " ; ] ; ] .
Solution 2: Use Pattern 10
Example R2RML Mapping for Solution 2
new article type, and also the SQL needed to execute the mappings.</p>
        <p>In solution 1, to add a new article type, a user just need to modify the SQL
query, appending the corresponding WHEN THEN pair statement. In solution
2, a new (parent) TriplesMap instance is needed for each article type. Then, in
the child TriplesMap, every article type needs a predicateObjectMap property.</p>
        <p>Now consider the following SPARQL query:
Solution 1 is the following:
SELECT ?s ?o WHERE f ?s ex:isAuthorOf ?o g. The resulting SQL query for
SELECT sid , ArticleType , aid FROM (</p>
        <p>SELECT s . s i d AS sid , a . aid AS aid , (CASE a . a r t i c l e t y p e</p>
        <p>WHEN ' ppr ' THEN ' Paper ' WHEN ' ths ' THEN ' Thesis ' ) AS ArticleType
FROM student s , a r t i c l e a WHERE s . s i d=a . author )</p>
        <p>The resulting SQL query for Solution 2 is the following:
SELECT sid , aid</p>
        <p>FROM student S , (SELECT author , aid FROM a r t i c l e WHERE a r t i c l e t y p e ='ppr ' ) P
WHERE S . s i d = P. author UNION
SELECT sid , aid
FROM student S , (SELECT author , aid FROM a r t i c l e WHERE a r t i c l e t y p e =' ths ' ) T
WHERE S . s i d = T. author</p>
        <p>Note that the generated SQL queries are very di erent and may have an
impact on query performance depending on the RDBMS.</p>
        <p>Related Patterns: Pattern 10, Pattern 11, Pattern 13</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Related Work</title>
      <p>
        In the (Object-Oriented) software community, patterns are used to describe
software design structures that can be used over and over again in di erent systems.
They provide a general solution that has to be applied in a particular context,
in which the design considerations serve to decide whether the pattern is
useful and how it could be implemented best [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. A kind of software patterns are
the re-engineering software patterns [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. These patterns describe how to change
a legacy system into a new, refactored system that ts current conditions and
requirements. Their main goal is to o er a solution for re-engineering
problems. They are also on a speci c level of abstraction, that describes a process of
re-engineering without proposing a complete methodology, and sometimes can
suggest which type of tool to use. Therefore RDB2RDF mappings can be seen
as re-engineering patterns because they map a legacy system (RDBMS) into a
new system (RDF).
      </p>
      <p>
        In the Semantic Web community, the Ontology Design Pattern portal4 has
been created in order to help in the design and quality of ontologies. Additionally,
Dodds and Davis presents a pattern catalogue for modeling, publishing and
consuming Linked Data [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. These Linked Data patterns do not include RDB2RDF
mapping patterns. Therefore our work is complemented by the Linked Data
patterns of Dodds and Davis. Furthermore, Hert et al. presents a comparison of the
expressivity of RDB2RDF mapping languages [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]. A framework for comparison
is introduced, which consists of a set of fteen features such as support for
different types of mappings, datatypes, named graphs, blank nodes etc. R2RML
supports all but one feature (write access) . Moreover, Rivero et al. presents
fteen RDF to RDF mapping patterns [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. Some of these patterns are speci c
to RDF to RDF mappings such as Remove Language Tag while others are not
applicable to RDB2RDF mappings such as Rename Class or Rename Property.
5
      </p>
    </sec>
    <sec id="sec-5">
      <title>Conclusions and Future Work</title>
      <p>In this paper, we have introduced fourteen RDB2RDF mapping patterns5, which
we have observed as reusable mapping throughout our experience as RDB2RDF
system developers and R2RML mapping authors. As previously mentioned, this
is a non-exhaustive list of mapping patterns and we aspire that the mapping
patterns presented in this paper serve as a starting point. We foresee new
mapping patterns in areas such as Named Graphs, Blank Nodes for anonymous or
sensitive data, Metadata, Languages, Datatypes. We hope that this work
encourages the Semantic Web community to further extend the RDB2RDF mapping
patterns.</p>
      <p>In certain patterns, we have identi ed two R2RML mapping solutions. These
solutions may or may not have performance issues. As future work, we will
4http://ontologydesignpatterns.org/
5The mappings are stored at http://mappingpedia.linkeddata.es/pattern/
DataPatterns/
thoroughly study the tradeo between mapping patterns and query performance.
Additionally, we will investigate the overlap between ontology design patterns,
linked data patterns, the feature set of Hert et al. and the RDF to RDF mapping
patterns of Rivero et al. with RDB2RDF mappings in general.</p>
      <p>Finally, we have to see how to align the proposed RDB2RDF mapping
patterns with Re-engineering Patterns category in the ODP Portal.
Acknowledgments: This work has been supported by the PlanetData,
BabelData, and myBigData projects. Juan F. Sequeda was supported by the NSF
Graduate Research Fellowship. We would like to kindly thank all W3C RDB2RDF
Working Group members. We thank Richard Cyganiak for discussions.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>M.</given-names>
            <surname>Arenas</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Bertails</surname>
          </string-name>
          ,
          <string-name>
            <surname>E.</surname>
          </string-name>
          <article-title>Prud'hommeaux, and</article-title>
          <string-name>
            <given-names>J.</given-names>
            <surname>Sequeda</surname>
          </string-name>
          .
          <article-title>Direct mapping of relational data to RDF</article-title>
          .
          <source>W3C Working Draft 29 May</source>
          <year>2012</year>
          , http://www.w3.org/TR/2012/WD-rdb
          <string-name>
            <surname>-</surname>
          </string-name>
          direct-mapping-
          <volume>20120529</volume>
          /.
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>S.</given-names>
            <surname>Das</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Sundara</surname>
          </string-name>
          , and
          <string-name>
            <given-names>R.</given-names>
            <surname>Cyganiak</surname>
          </string-name>
          . R2rml:
          <article-title>Rdb to rdf mapping language</article-title>
          .
          <source>W3C Working Draft 29 May</source>
          <year>2012</year>
          , http://www.w3.org/TR/2012/WD-r2rml-
          <volume>20120529</volume>
          /.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>L.</given-names>
            <surname>Dodds</surname>
          </string-name>
          and
          <string-name>
            <given-names>I.</given-names>
            <surname>Davis</surname>
          </string-name>
          .
          <article-title>Linked data patterns-a pattern catalogue for modelling, publishing, and consuming linked data</article-title>
          . http://patterns.dataincubator.org/book/,
          <year>2011</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>H.</given-names>
            <surname>Edwards</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Puckett</surname>
          </string-name>
          ,
          <article-title>and</article-title>
          <string-name>
            <given-names>A.</given-names>
            <surname>Jolly</surname>
          </string-name>
          .
          <article-title>Analyzing Communication Patterns in Software Engineering Projects</article-title>
          .
          <source>In Software Engineering Research and Practice</source>
          , pages
          <volume>310</volume>
          {
          <fpage>315</fpage>
          ,
          <year>2006</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>M.</given-names>
            <surname>Hert</surname>
          </string-name>
          , G. Reif, and
          <string-name>
            <given-names>H. C.</given-names>
            <surname>Gall</surname>
          </string-name>
          .
          <article-title>A comparison of rdb-to-rdf mapping languages</article-title>
          .
          <source>In Proceedings of the 7th International Conference on Semantic Systems</source>
          ,
          <year>2011</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>R.</given-names>
            <surname>Pooley</surname>
          </string-name>
          and
          <string-name>
            <given-names>P.</given-names>
            <surname>Stevens</surname>
          </string-name>
          .
          <source>Software Reengineering Patterns. Technical report</source>
          ,
          <year>1998</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <given-names>C. R.</given-names>
            <surname>Rivero</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Schultz</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Bizer</surname>
          </string-name>
          , and
          <string-name>
            <given-names>D.</given-names>
            <surname>Ruiz</surname>
          </string-name>
          .
          <article-title>Benchmarking the performance of linked data translation systems</article-title>
          .
          <source>In Proceedings of the 5th Linked Data on the Web Workshop (LDOW)</source>
          ,
          <year>2012</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <given-names>J. F.</given-names>
            <surname>Sequeda</surname>
          </string-name>
          and
          <string-name>
            <given-names>D. P.</given-names>
            <surname>Miranker</surname>
          </string-name>
          . Ultrawrap:
          <article-title>Sparql execution on relational data</article-title>
          .
          <source>Technical Report TR-12-10</source>
          , The University of Texas at Austin, Department of Computer Sciences,
          <year>2012</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <given-names>B.</given-names>
            <surname>Villazon-Terrazas</surname>
          </string-name>
          and
          <string-name>
            <given-names>M.</given-names>
            <surname>Hausenblas</surname>
          </string-name>
          .
          <article-title>R2rml and direct mapping test cases</article-title>
          .
          <source>W3C Editor's Draft 24 July</source>
          <year>2012</year>
          , http://www.w3.org/2001/sw/rdb2rdf/test-cases/.
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>