# xR2RML: Relational and Non-Relational Databases to RDF Mapping Language

Franck Michel, Loïc Djimenou, Catherine Faron Zucker, Johan Montagnat

► To cite this version:

Franck Michel, Loïc Djimenou, Catherine Faron Zucker, Johan Montagnat. xR2RML: Relational and Non-Relational Databases to RDF Mapping Language. [Research Report] ISRN I3S/RR 2014-04-FR, CNRS. 2017. [hal-01066663v5](https://hal.science/hal-01066663v5)

HAL Id: hal-01066663

https://hal.science/hal-01066663v5

Submitted on 26 Oct 2017

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
LABORATOIRE

<figure><img src="image_2.png" /></figure>

INFORMATIQUE, SIGNAUX ET SYSTÈMES
DE SOPHIA ANTIPOLIS
UMR7271

# xR2RML: Relational and Non-Relational Databases
to RDF Mapping Language

Franck Michel, Loïc Djimenou, Catherine Faron-Zucker, Johan Montagnat

Equipe SPARKS

Rapport de Recherche ISRN I3S/RR 2014-04-FR

## Document history:

<table><thead><tr><td>Version</td><td>Date</td><td>Description</td></tr></thead><tbody><tr><td>v1</td><td>2014-09-22</td><td>Initial version</td></tr><tr><td>v2</td><td>2014-10-08</td><td>Fix spelling mistakes.</td></tr><tr><td>v3</td><td>2014-10-20</td><td>Convergence with RML language definitions, moving of reference formulation from language to processor environment, fix misc. minor mistakes.</td></tr><tr><td>V4</td><td>2016-11-07</td><td>Add property xrr:uniqueRef in logical source. Many rewordings and clarifications.</td></tr><tr><td>V5</td><td>2017-10-25</td><td>Add property xrr:pushDown in logical source and nested term map</td></tr></tbody></table>

Laboratoire d'Informatique, Signaux et Systèmes de Sophia-Antipolis (I3S) - UMR7271 - UNS CNRS
2000, route des Lucioles - Les Algorithmes - bât. Euclide B 06900 Sophia Antipolis - France
http://www.i3s.unice.fr
<table><tbody><tr><td>1</td><td>Introduction</td><td>4</td></tr><tr><td>1.1</td><td>Document Conventions</td><td>4</td></tr><tr><td>1.2</td><td>Query Languages and Data Models</td><td>4</td></tr><tr><td>1.3</td><td>xR2RML mapping graphs and mapping documents</td><td>6</td></tr><tr><td>1.4</td><td>xR2RML processors</td><td>6</td></tr><tr><td>2</td><td>xR2RML Overview and Examples</td><td>8</td></tr><tr><td>2.1</td><td>Mapping CSV data</td><td>8</td></tr><tr><td>2.2</td><td>Mapping JSON data</td><td>9</td></tr><tr><td>2.3</td><td>Mapping XML data</td><td>10</td></tr><tr><td>2.4</td><td>Mapping data with mixed formats</td><td>11</td></tr><tr><td>2.5</td><td>Generating an RDF collection from a list of values</td><td>12</td></tr><tr><td>2.6</td><td>Generating an RDF container with a referencing object map</td><td>13</td></tr><tr><td>3</td><td>Language description</td><td>15</td></tr><tr><td>3.1</td><td>Mapping Logical Sources to RDF with Triples Maps</td><td>15</td></tr><tr><td>3.1.1</td><td>xR2RML Triples Map</td><td>15</td></tr><tr><td>3.1.2</td><td>Defining a Logical Source</td><td>15</td></tr><tr><td>3.1.3</td><td>xR2RML Triples Map Iteration Model</td><td>19</td></tr><tr><td>3.2</td><td>Creating RDF terms with Term Maps</td><td>22</td></tr><tr><td>3.2.1</td><td>xR2RML Term Maps</td><td>22</td></tr><tr><td>3.2.1.1</td><td>Constant-, Column-, Reference- and Template-valued Term Maps</td><td>22</td></tr><tr><td>3.2.1.2</td><td>Term Types of Term Maps</td><td>23</td></tr><tr><td>3.2.1.3</td><td>Nested Term Maps</td><td>23</td></tr><tr><td>3.2.2</td><td>Referencing data elements</td><td>25</td></tr><tr><td>3.2.2.1</td><td>Referencing simple data elements</td><td>25</td></tr><tr><td>3.2.2.2</td><td>Referencing data elements with mixed data formats</td><td>26</td></tr><tr><td>3.2.2.3</td><td>Production of multiple RDF terms</td><td>28</td></tr><tr><td>3.2.2.4</td><td>Production of RDF collections or containers</td><td>31</td></tr><tr><td>3.2.3</td><td>Parsing nested structured values</td><td>34</td></tr><tr><td>3.2.4</td><td>Multiple Mapping Strategies</td><td>36</td></tr><tr><td>3.2.5</td><td>Default Term Types</td><td>37</td></tr><tr><td>3.3</td><td>Reference relationships between logical sources</td><td>38</td></tr><tr><td>3.3.1</td><td>Reference relationship with structured values</td><td>40</td></tr><tr><td>3.3.2</td><td>Generating RDF collection/container with a referencing object map</td><td>41</td></tr><tr><td>3.3.3</td><td>Generating RDF collection/container with a referencing object map in the relational case</td><td>44</td></tr></tbody></table>
<table><tr><td>4</td><td>References</td><td>46</td></tr></table>
# 1 Introduction

This document describes xR2RML, a language for expressing customized mappings from various types of databases (XML, object-oriented, NoSQL) to RDF datasets.

xR2RML is an extension of the R2RML [1] mapping language, and relies on some properties of the RML mapping language [4][3]. R2RML addresses the mapping of relational databases to RDF. RML extends R2RML to address the mapping of heterogeneous data formats (CSV, XML, JSON) to RDF, but does not investigate the constraints that arise when dealing with different types of heterogeneous databases. xR2RML extends this scope to a wide range of non-relational databases. This document leverages the R2RML specification and mainly describes extensions. It also leverages the RML specification [2] (Draft, 17 Sept. 2014), either explicitly reusing RML properties when applicable, or by extending existing properties. Consequently, the reader should have a good understanding of both R2RML and RML before reading this document.

xR2RML is backward compatible with R2RML.

## 1.1 Document Conventions

In this document, examples assume the following namespace prefix bindings unless otherwise stated:

<table><thead><tr><td>Prefix</td><td>IRI</td></tr></thead><tbody><tr><td>rr:</td><td>http://www.w3.org/ns/r2rml#</td></tr><tr><td>rml:</td><td>http://semweb.mmlab.be/ns/rml#</td></tr><tr><td>ql:</td><td>http://semweb.mmlab.be/ns/ql#</td></tr><tr><td>xrr:</td><td>http://www.i3s.unice.fr/ns/xr2rml#</td></tr><tr><td>rdf:</td><td>http://www.w3.org/1999/02/22-rdf-syntax-ns#</td></tr><tr><td>rdfs:</td><td>http://www.w3.org/2000/01/rdf-schema#</td></tr><tr><td>xsd:</td><td>http://www.w3.org/2001/XMLSchema#</td></tr><tr><td>ex:</td><td>http://example.com/ns#</td></tr></tbody></table>

Vocabulary definitions are formatted in such grey boxes:

Definition

## 1.2 Query Languages and Data Models

R2RML is specifically focused on the translation of relational databases into RDF datasets. xR2RML extends this scope to non-relational databases. Although it is illusory to seek universal support of any database, our endeavor is to equally support most common relational and non-relational databases. In our approach, we
more specifically analyze the requirements to support NoSQL and XML databases. Yet, xR2RML may not support all NoSQL databases, given the large variety of systems behind this word. Nevertheless, we argue that our work can be generalized to some other types of database, for instance object-oriented and directory (LDAP) databases.

**Query languages:**

Relational databases all support ANSI SQL (or at least a subset of it), and most XML databases support XQuery and XPath (which is subset of XQuery). By contrast, NoSQL is a catch-all term referring to very diverse systems [6][5]. They have heterogeneous access methods ranging from low-level APIs to expressive query languages. Despite several propositions of common query language (N1QL<fnref n="1" />, UnQL<fnref n="2" />, SQL++ [8], ArangoDB Query Language<fnref n="3" />, CloudMdsQL[7]), no consensus has emerged yet, that would fit most NoSQL databases. Therefore, until a standard eventually arises, xR2RML must be agile enough to cope with various query languages and protocols.

Remark: R2RML relies on the ability of relational databases to support a declarative query language. xR2RML does the same assumption with regards to other types of databases, although this may be limitative. For instance, most NoSQL key-value stores provide simple key-based operations (such as put, get, delete) by means of APIs used in imperative programming languages, but they hardly provide a declarative query language. If such a system is to be mapped to RDF using xR2RML, an xR2RML processor should implement a mechanism to bridge this gap. In other words the xR2RML processor should define its own query language to be interpreted and compiled using an imperative programming language.

**Data models:**

Relational databases comply with a row-based model in which all rows have the same columns.

NoSQL systems have heterogeneous data models (key-value store, document store, extensible column-store, graph store). Some of them also comply with the row-based model, such as extensible column-stores (also known as column family stores) with the difference that all rows do not necessarily share the same columns (BigTables, Cassandra...). Other databases in which data is formatted in JSON (document stores such as MongoDB, CouchDB...) or XML (native XM databases such as BaseX, eXistDB) can hardly be reduced to a row-based model. JSON or XML documents consist of structured (hierarchical) values representing collections or key-value associations:

* A JSON dictionary is an ordered association of keys and values, both keys and values may be of any type. A JSON array is an ordered collection of elements, it is a specific case of dictionary in which keys are implicit integer indexes: 0, 1, 2, etc.

* Similarly, a set of XML elements having the same parent element can be seen as an ordered association of keys (element names) and values (element values). A set of XML elements of the same

<footnote n="1">¹ http://www.couchbase.com/communities/n1ql</footnote>

<footnote n="2">² http://unql.sqlite.org/index.html</footnote>

<footnote n="3">³ http://docs.arangodb.org/Aql/README.html</footnote>
type, having the same parent element, can be seen as an ordered collection. Besides, attributes of an XML element can be seen as a specific type of key-value association.

The model of structured values described above for JSON and XML can easily be applied to other databases. In an object-oriented model, an object can be approximated by as a key-value association: keys are attribute names while values are either a scalar, another object (composition or aggregation relationship), or a collection (depending on capabilities of the modeling language: list, map, etc). Similarly, an LDAP directory is organized as a tree. Each node has an identifier and a set of attributes represented as "name=value" that are nothing else than a key-value association. A set of attributes with the same name can be interpreted as either as a collection or a key-value association in which keys are not unique. Thus, xR2RML must be able to map data elements from rows as well as structured values (nested collections and key-value associations) to RDF terms.

**Note:** Below, we shall use the term "structured values" to refer to collections and key-value associations, whatever the representation syntax used.

## 1.3 xR2RML mapping graphs and mapping documents

An **xR2RML mapping** defines a mapping from a database to RDF; it is represented as an RDF graph called an **xR2RML mapping graph**.

An **xR2RML mapping document** is any document written in the Turtle RDF syntax that encodes an xR2RML mapping graph.

Any R2RML mapping graph is a valid xR2RML mapping graph (backward compatibility).

## 1.4 xR2RML processors

An **xR2RML processor**, or **processing engine**, is a system that, given an xR2RML mapping and an input database, provides access to the output RDF dataset.

An **xR2RML processor** has access to an execution environment consisting of:

* An **xR2RML mapping document**, as defined above.

* A **connection** to the input database, used by the xR2RML processor to evaluate queries against the input database. It must be established with sufficient privileges for read access to all database elements (tables, views, documents, objects...) that are referenced in the xR2RML mapping.

* A **reference formulation** (optional): this concept, introduced by RML, names a syntax used to reference data elements within results of a query run against the database connection. The reference formulation is not mentioned in the mapping language, but is typically provided as configuration parameter. If it is not provided, it defaults to "column name" in order to ensure backward compatibility with R2RML.

* A **query language identifier** (optional) identifies which query language shall be used to query the database, in case several languages are supported.
* A **base IRI** used in resolving relative IRIs produced by the xR2RML mapping (optional).

It is the responsibility of an xR2RML processor developer to document how to provide the processor with
this context information.
# 2 xR2RML Overview and Examples

This section gives a brief overview of the xR2RML mapping language, followed by simple examples of mapping various types of database to RDF.

An xR2RML mapping refers to logical sources to retrieve data from the input database. A logical source can be either an *xR2RML base table* (for input databases where tables or views exist, such as SQL views), or an *xR2RML view* representing the result of executing a query against the input database. An xR2RML processor is provided an xR2RML mapping description, a connection to the database and a reference formulation that specifies the syntax used to refer to data elements retrieved from the input database: this can be a column name in the case of row-based systems (RDB, extensible column-store), a JSONPath expression in case of a NoSQL document store, an XPath expression in case of an XML native database, an LDAP path in case of an LDAP directory, etc.

Each logical source is mapped to RDF using a triples map. As in R2RML, a triples map consists of a subject map that generates the subject of all RDF triples that will be generated from data elements, and multiple predicate-object maps that produce the predicate and object terms of triples.

## 2.1 Mapping CSV data

The input database in the example below consists of one CSV document. It is assumed that the xR2RML processor is provided a connection to that file, e.g. by means of a descriptor to a file on the local file system or a URL to locate the file on a web server. Data elements will be referenced using column names, i.e. the reference formulation passed to the xR2RML processor.

As a CSV file simply consists of a single unnamed table, the logical source can simply be left empty.

<table><tr><td>Input data</td><td>title, year, director<br/>Manhattan, 1979, Woody Allen<br/>Annie Hall, 1979, Woody Allen<br/>2046, 2004, Wong Kar-wai<br/>In the Mood for Love, 2000, Wong Kar-wai</td></tr><tr><td>Mapping graph</td><td>&lt;#CSVTriplesMap&gt;<br/>rr:subjectMap [rr:template "http://example.org/movie/{title}"];]<br/>rr:predicateObjectMap [<br/>rr:predicate ex:directedBy;<br/>rr:objectMap [ xrr:reference "director" ];]<br/>].</td></tr><tr><td>RDF triples</td><td>&lt;http://example.org/movie/Manhattan&gt; ex:directedBy "Woody Allen".</td></tr></table>
<table><tr><td>produced</td><td>&lt;http://example.org/movie/Annie%20Hall&gt; ex:directedBy "Woody Allen".<br/>&lt;http://example.org/movie/2046&gt; ex:directedBy "Wong Kar-wai".<br/>&lt;http://example.org/movie/In%20the%20Mood%20for%20Love&gt; ex:directedBy "Wong Kar-wai".</td></tr></table>

## 2.2 Mapping JSON data

The input database in the example below is a MongoDB database (document store). The query in the logical source uses the proprietary JavaScript-based query language of MongoDB. It retrieves one JSON document from collection "movies", that lists movie directors and movies they directed.

Without further instruction on how to parse the document, JSONPath expressions referring to data elements in the subject and object map will be evaluated against the whole document. For instance, a subject using expression "$.directors.name" will return two terms, while an object map using expression "$.directors movies.*" will return four terms, one for each movie whatever its director. This will result in mixing up directors and movies. To avoid this, an rml:iterator property is added to the logical source, specifying that the triples map iteration should occur on each element of the array of directors.

References to data elements (rr:template, xrr:reference), as well as the iterator pattern, are expressed in JSONPath (i.e. the reference formulation, passed to the xR2RML processor along with the database connection).

<table><tr><td>Input data</td><td>{ "directors": [ { "name": "Wong Kar-wai", "movies": ["2046", "In the Mood for Love"] }, { "name": "Woody Allen", "movies": ["Manhattan", "Annie Hall"] } ]}</td></tr><tr><td>Mapping graph</td><td>&lt;#Directors&gt;<br/>xrr:logicalSource [ xrr:query "dbFind({ directors: { $exists: true } })"; rml:iterator "$.directors.*"; ];<br/>rr:subjectMap [ rr:template "http://example.org/director/ ${.name}"; ];<br/>rr:predicateObjectMap [ rr:predicate ex:directed; rr:objectMap [ xrr:reference "$.movies.*"; ]; ].</td></tr><tr><td>RDF triples produced</td><td>&lt;http://example.org/director/Woody%20Allen&gt; ex:directed "Manhattan".<br/>&lt;http://example.org/director/Woody%20Allen&gt; ex:directed "Annie Hall".</td></tr></table>
<http://example.org/director/Wong%20Kar-wai> ex:directed "2046".
<http://example.org/director/Wong%20Kar-wai> ex:directed "In the Mood for Love".

## 2.3 Mapping XML data

The example below is very similar to the previous one, using an XML database supporting XQuery. The query in the logical source retrieves "director" XML elements. As in the previous example, to avoid mixing up directors and movies, an rml:iterator property is added to the logical source, specifying that the triples map iteration should occur on each "director" XML element.

References to data elements (rr:template, xrr:reference), as well as the iterator pattern, use the XPath syntax (i.e. the reference formulation, passed to the xR2RML processor along with the database connection).

<table><tr><td>Input data</td><td>< directors> < director name="Wong Kar-wai"> < movies> < movie>2046</ movie> < movie>In the Mood for Love</ movie> </ movies> </ director> < director name="Woody Allen"> < movies> < movie>Manhattan</ movie> < movie>Annie Hall</ movie> </ movies> </ director> </ directors></table><table><tr><td>Mapping graph</td><td><#Directors> xrr:logicalSource [ """for $i in //directors/director where $i/country eq "China" return $i; """; ]; rr:subjectMap [ rr:template "http://example.org/director/{/director/@name}"; ]; rr:predicateObjectMap [ rr:predicate ex:directed;</td></tr></table>
<table><tr><td></td><td>rr:objectMap [ xrr:reference "/movie"; ];<br/>].</td></tr><tr><td>RDF triples<br/>produced</td><td>&lt;http://example.org/director/Woody%20Allen&gt; ex:directed "Manhattan".<br/>&lt;http://example.org/director/Woody%20Allen&gt; ex:directed "Annie Hall".<br/>&lt;http://example.org/director/Wong%20Kar-wai&gt; ex:directed "2046".<br/>&lt;http://example.org/director/Wong%20Kar-wai&gt; ex:directed "In the Mood for Love".</td></tr></table>

## 2.4 Mapping data with mixed formats

In some use cases, it is common to store values in a format which is not the native database format. For instance, an application designer may choose to embed JSON, CSV, or XML values in the cells of a relational database, for performance concerns or application design constraints.

xR2RML allows to reference data elements within such mixed contents with *mixed-syntax paths*. A path with mixed-syntax consists of the concatenation of several path expressions separated by the slash '/' character. Each individual path is enclosed in a syntax path constructor: Column(column-name), CSV(column-name), TSV(column-name), JSONPath(JSONPath-expression), XPath(XPath-expression).

In the example below, the logical source is a relational table with two columns. The second column, Movies, holds values formatted as JSON arrays. The xrr:reference property of the object map uses a mixed-syntax path: Column(Movies)/JSONPath($.*). This expression selects values from column "Movies" and evaluates JSONPath expression "$.*" against the values.

<table><tr><td>Input data</td><td>Table DIRECTORS:<table><thead><tr><td>Name</td><td>Movies</td></tr></thead><tbody><tr><td>Wong Kar-wai</td><td>"2046", "In the Mood for Love"</td></tr><tr><td>Woody Allen</td><td>"Manhattan", "Annie Hall"</td></tr></tbody></table></td></tr><tr><td>Mapping graph</td><td>&lt;#Directors&gt;<br/>rr:logicalTable [<br/>rr:tableName "DIRECTORS";<br/>];<br/>rr:subjectMap [ rr:template "http://example.org/director/{Name}"; ];<br/>rr:predicateObjectMap [<br/>rr:predicate ex:directed;<br/>rr:objectMap [ xrr:reference "Column(Movies)/JSONPath($.*)"; ];</td></tr></table>
<table><tr><td>RDF triples produced</td><td></td></tr><tr><td></td><td>&lt;http://example.org/director/Woody%20Allen&gt; ex:directed "Manhattan".<br/>&lt;http://example.org/director/Woody%20Allen&gt; ex:directed "Annie Hall".<br/>&lt;http://example.org/director/Wong%20Kar-wai&gt; ex:directed "2046".<br/>&lt;http://example.org/director/Wong%20Kar-wai&gt; ex:directed "In the Mood for Love".</td></tr></table>

## 2.5 Generating an RDF collection from a list of values

As illustrated by the previous example, several RDF terms can be generated by a term map during one triples map iteration step. While this can lead to the generation of several triples, this can also be used to generate hierarchical values in the form of RDF collections or containers.

The example below was already presented in section 2.2. In the object map we simply add an `rr:termType` property with value `xrr:RdfList`. All RDF terms produced by the object map during one triples map iteration step are then grouped as members of one term of type `rdf:List` (denoted as `"(a b c...)")` in Turtle syntax).

Additionally, assume we want to add a language tag to the movie titles. The object map describes the generation of RDF lists, hence it would not make sense to add an `rr:language` property. To state properties about the members of the generated RDF list, we need a nested term map, introduced by the `xrr:nestedTermMap` property. A nested term map accepts the same properties as a term map, but it applies to members of RDF collection/container terms generated by its parent term map.

<table><tr><td>Input data</td><td><pre>{ "directors": [ { "name": "Wong Kar-wai", "movies": ["2046", "In the Mood for Love"] }, { "name": "Woody Allen", "movies": ["Manhattan", "Annie Hall"] } ]}</pre></td></tr><tr><td>Mapping graph</td><td><pre>&lt;#Directors&gt;<br/>xrr:logicalSource [<br/>xrr:query "dbgeben( { directors: { $exists: true } } )";<br/>rml:iterator "$.directors.*";<br/>];<br/>rr:subjectMap [ rr:template "http://example.org/director/{$.name}"; ];<br/>rr:predicateObjectMap [<br/>rr:predicate ex:directed;<br/>rr:objectMap [<br/>xrr:reference "$.movies.*";<br/>rr:termType xrr:RdfList;<br/>xrr:nestedTermMap [ rr:language "en"; ]]</pre></td></tr></table>
<table><tr><td></td><td>] ;<br/>].</td></tr><tr><td>RDF triples produced</td><td>&lt;http://example.org/director/Woody%20Allen&gt; ex:directed [<br/>a rdf:List;<br/>rdf:_1 "Manhattan"@en;<br/>rdf:_2 "Annie Hall"@en;<br/>]<br/>&lt;http://example.org/director/&lt;Wong%20Kar-wai&gt; ex:directed<br/>( "2046"@en "In the Mood for Love"@en ).</td></tr></table>

## 2.6 Generating an RDF container with a referencing object map

The example below uses a referencing object map to describe a cross-reference relationship between logical resources. In addition, it generates an RDF bag from the result of the join condition in the referencing object map.

Triples map `<#Movies>` generates IRIs for the movies. The referencing object map in triples map `<#Directors>` uses IRI generated in triples map `<#Movies>` as the members of an RDF bag (property `rr:term:Type` `xrr:RdfBag`).

The join condition in triples map `<#Directors>` produces a result if a movie title (`rr:parent "$.title"`) matches at least one movie in the list of movies associated with each director (`rr:child "$.movies.*"`).

<table><tr><td>Input data</td><td><pre>{ "directors": [ <br/>  { "name": "Wong Kar-wai", "movies": ["2046", "In the Mood for Love"] }, <br/>  { "name": "Woody Allen", "movies": ["Manhattan", "Annie Hall"] } <br/> ]}<pre><br/>{ "movies": [ <br/>  { "title": "Manhattan", "year": "1979" }, <br/>  { "title": "Annie Hall", "year": "1977" }, <br/>  { "title": "2046", "year": "2004" }, <br/>  { "title": "In the Mood for Love", year: "2000" } <br/> ]}</pre></td></tr><tr><td>Mapping graph</td><td><pre>&lt;#Movies&gt;<br/>xrr:logicalSource [</pre></td></tr></table>
xrr:query "db Balance.find( { movies: { $exists: true } } )";

rml:iterator "$.movies.*";
];

rr:subjectMap [ rr:template "http://example.org/movies/ {$ .title}" ];

<#Directors>
xrr:logicalSource [
xrr:query "db Balance.find( { directors: { $exists: true } } )";
rml:iterator "$.directors.*";
];

rr:subjectMap [ rr:template "http://example.org/director/ {$ .name}" ];

rr:predicateObjectMap [
    rr:predicate ex:directed;
    rr:objectMap [
        rr:parentTriplesMap <#Movies>;
        rr:joinCondition [
            rr:child "$.movies.*";
            rr:parent "$.title";
        ];
        rr:termType xrr:RdfBag;
    ];
].

Generated RDF triples

<http://example.org/director/Woody%20Allen> ex:directed [
a rdf:Bag;
rdf:_1 <http://example.org/movie/Manhattan>";
rdf:_1 <http://example.org/movie/Annie%20Hall>. 
].

<http://example.org/director/<Wong%20Kar-wai> ex:directed [
a rdf:Bag;
rdf:_1 <http://example.org/movie/2046>";
rdf:_2 <http://example.org/movie/In%20the%20Mood%20for%20Love>. 
].
# 3 Language description

## 3.1 Mapping Logical Sources to RDF with Triples Maps

### 3.1.1 xR2RML Triples Map

An xR2RML triples map specifies a rule for translating data elements of a logical source to zero or more RDF triples. The RDF triples generated from one data element (row, document, set of XML elements, etc.) in the logical source all share the same subject.

An xR2RML triples map extends R2RML triples map by referencing a logical source (next section) instead of a logical table. An xR2RML triples map is represented by a resource that references the following resources:

* It must have exactly one **xrr:logicalSource** property. Its object is a logical source that specifies a table or a query result to be mapped to triples.

* It must have exactly one subject map that specifies how to generate a subject for each data element of the logical source (row, document, set of XML elements, etc.). A subject map may be specified in two ways:

- using the rr:subjectMap property, whose value must be the subject map, or

- using the constant shortcut property rr:subject.

* It may have zero or more rr:predicateObjectMap properties, whose values must be predicate-object maps. They specify pairs of predicate maps and object maps that, together with the subjects generated by the subject map, may form one or more RDF triples for each data element.

### 3.1.2 Defining a Logical Source

**R2RML logical table:** An R2RML logical table is a data set on which a triples map applies: this may be a relational table, an SQL view, or the result of a valid SQL query (property rr:sqlQuery).

**RML logical source:**

- An RML logical source extends the R2RML logical table. It points to a source containing the data to be mapped, denoted by property rml:source. In some cases, it brings database connection details (such as the protocol, URL or login provided by a connection string) into the mapping. Whereas this enables several triples maps to refer to different data sources, it opposes the implicit R2RML idea that such specificities should be kept out of the scope of the mapping. Besides, it is unclear how this property relates to property rml:query. The latter is defined in the RML ontology, although it is not described or exemplified in the language specification nor in RML Web pages. It is only briefly mentioned in an article [Dimou et al., 2013] where authors propose that property rml:query subsume properties rr:sqlQuery and rml:xmlQuery. But this conflicts with requirement 2 since a specific property has to be defined for each supported query language.

- The RML reference formulation concept (property rml:referenceFormulation) of an RML logical source names the syntax of data element reference syntaxes (ql:CSV, ql:JSONPath, ql:XPath, ql:CSS3 and
rr:SQL2008). This binds the mapping language with a predefined set of syntaxes, which conflicts with
requirement 1 and hampers the extensibility to a wider scope of database.

The discussion above underlines that it would not be suitable for xR2RML to extend RML's logical source concept. Instead, the xR2RML logical source extends the R2RML logical table, while relevant RML properties are used or extended separately.

Below we define the xR2RML logical source that extends the R2RML logical source to cope with a wider
scope of input databases as well as richer iteration models detailed in section 3.1.3.

A **logical source** (property `xrr:logicalSource`) extends the R2RML concept of logical table (property `rr:logicalTable`) in the case of non-relational databases. A logical source is the result of a query applied to the input database, to be mapped to RDF triples. A logical source is either an **xR2RML base table** or an **xR2RML view**.

An **xR2RML base table** is a logical source containing data from a table in the input database. It simply extends the concept of *R2RML table or view* to the context of tabular databases beyond relational databases (e.g. CSV, extensible column store). An xR2RML base table is represented by a resource that has exactly one **rr:tableName** property. Its object is a string literal representing the table name.

An **xR2RML view** is a logical source whose content is the result of executing a query against the input database. It is represented by a resource that has exactly one **xrr:query** property. Property `xrr:query` extends RML property `rml:query`. The object of property `xrr:query` is a string literal representing a valid expression with regards to the query language supported by the input database.

A logical source may have one data property **rml:iterator** that specifies the *iteration pattern* to apply on data retrieved from the input database (section 3.1.3). Its object is an expression written using the reference formulation (section 1.4). The rml:iterator property is ignored in the context of tabular result sets in which data is accessed by column names.

An rml:iterator property may be complemented with any number of `xrr:pushDown` properties (section 3.1.3) that specify how some values must be added within the documents that result of the rml:iterator. The object of a `xrr:pushDown` property is an instance of the `xrr:PushDown` class, that must have exactly one `xrr:reference` property and one `xrr:as` property.

A logical source may have any number of **xrr:uniqueRef** properties that specify a *unique data element reference* within the documents retrieved by the `xrr:query` property. This property may be used for query optimization when rewriting a SPARQL query into the target database query language. The unique data element reference is an expression written according to the syntax specified by the reference formulation (section 1.4).
REST-based web service returning an XML stream based on parameters passed in the HTTP GET query string. The service URL (e.g. http://example.org/service) and XPath reference formulation are passed to the xR2RML processor by configuration, while the HTTP query string is provided by the xrr:query property.

XML database supporting XQuery.
XPath is used to describe the iterator and later on to refer to data elements within the XML data returned by the database.

JSON file. The xR2RML processor is provided with file URL and the JSONPath reference formulation. No further query is required (no xrr:query property). An iterator defines the pattern to iterate on.

MongoDB database (document store). MongoDB Shell Query Language is used to search for documents in collection "movies". Then, JSONPath is used to refer to data elements within the JSON documents returned by the database.

Cassandra (extensible column store) using Cassandra Query Language (CQL). Data element are referenced by column name (reference formulation passed to the xR2RML processor).

AllegroGraph (RDF graph store) using SPARQL.
The column name reference formulation is applied to a SPARQL result set: the result set is considered as a table in which columns are named after variable names.

[] xrr:logicalSource [
xrr:query "?minYear=1980&limit=10";
rml:iterator "/movie";
];

[] xrr:logicalSource [
xrr:query """"for $i in //movies/movie
where $i/year gt 1980
order by $i/@title
return $i/@title""";
rml:iterator "/movie";
];

[] xrr:logicalSource [
rml:iterator "$.movies.*";
];

[] xrr:logicalSource [
xrr:query """db.find({"year":"$gt: 1980"})""";
xrr:uniqueRef "$.movield"
];

[] xrr:logicalSource [
xrr:query """"SELECT TITLE, YEAR FROM Movies
LIMIT 10""";
];

[] xrr:logicalSource [
xrr:query """"select ?title ?year
where { ?movie a ex:Movie;
ex:name ? title;
ex:year ?year. }
filter (?year > "1980"^^xsd:integer)
order by ?year
limit 10""";
];
### 3.1.3 xR2RML Triples Map Iteration Model

In R2RML, the row-based iteration implicitly occurs on a set of rows read from a logical table. xR2RML applies this principle to other row-based systems such as CSV/TSV files and extensible column stores, but also SPARQL result sets as already mentioned. In the context of non row-based databases, the model is implicitly extended to a **document-based iteration model**: a document is one result of a result set, whatever the form of such a result. Typically, the document-based iteration applies to a set of JSON documents retrieved from a NoSQL document store, or a set of XML documents retrieved from an XML database. In the case of data sources that do not natively provide iterators over results, for instance a simple XML file or a web service returning an XML stream at once, then a single iteration occurs on the whole document retrieved.

The document-based iteration model alone may not be sufficient to fulfill any iteration needs. This is particularly true for **hierarchical data models** such as JSON and XML. Let us consider the JSON document below that describes movie directors and respective movies:

```json
{
  "type": 3,
  "directors": [ {
    "name": "Wong Kar-wai",
    "movies": [ "2046", "In the Mood for Love" ]
  },
  {
    "name": "Woody Allen",
    "movies": [ "Manhattan", "Annie Hall" ]
  }
]}
```

We consider the following xR2RML following mapping graph:

```xml
<#Directors>
  xrr:logicalSource [ xrr:query "db Balance.find( { directors: { $exists: true } } )" ];
  rr:subjectMap [ rr:template "http://example.org/director/${.name}"; ];
  rr:predicateObjectMap [
    rr:predicate ex:directed;
    rr:objectMap [ xrr:reference "$.directors.*.movies.*"; ];
  ].
</#Directors>
```

In this mapping, the subject map returns two terms (one per director) while the object map returns four terms (one per movie in the document). Consequently, triples are generated that mix up all directors and movies:

```
<http://example.org/director/Woody%20Allen> ex:directed "Manhattan".
<http://example.org/director/Woody%20Allen> ex:directed "Annie Hall".
<http://example.org/director/Woody%20Allen> ex:directed "2046".
<http://example.org/director/Woody%20Allen> ex:directed "In the Mood for Love".
```
<http://example.org/director/Wong%20Kar-wai> ex:directed "Manhattan".
<http://example.org/director/Wong%20Kar-wai> ex:directed "Annie Hall".
<http://example.org/director/Wong%20Kar-wai> ex:directed "2046".
<http://example.org/director/Wong%20Kar-wai> ex:directed "In the Mood for Love".

To deal with such cases, xR2RML relies on the concept of iterator defined in RML:

An **iterator** is defined within an xR2RML logical source by means of the **rml:iterator** property. It specifies the iteration pattern to apply to data retrieved from the input database. The object of an rml:iterator property is a valid path expression written using the reference formulation (section 1.4).

With the rml:iterator property, the previous example is modified as shown below:

<#Directors>
xrr:logicalSource [
xrr:query "dbFind( { directors: { $exists: true } } )";
rml:iterator "$.directors.*";
];
rr:subjectMap [ rr:template "http://example.org/director/{$.name}" ];
rr:predicateObjectMap [
rr:predicate ex:directed;
rr:objectMap [ xrr:reference "$.movies.*" ];
].

The rml:iterator property indicates that, within the document retrieved, the triples map iteration should be
performed on each director element rather than on the whole document. The iterator now yields **two**
**separate documents**:

{ "name": "Wong Kar-wai", "movies": ["2046", "In the Mood for Love"] }
{ "name": "Woody Allen", "movies": ["Manhattan", "Annie Hall"] }

Finally, the first document yields the first two triples below, while the second document yields the 3<sup>rd</sup> and 4<sup>th</sup> triples:

<http://example.org/director/Woody%20Allen> ex:directed "Manhattan".
<http://example.org/director/Woody%20Allen> ex:directed "Annie Hall".
<http://example.org/director/Wong%20Kar-wai> ex:directed "2046".
<http://example.org/director/Wong%20Kar-wai> ex:directed "In the Mood for Love".

Let us now assume that we would like field "type" (whose value is 3, whatever this means) to be part of the
subject terms, e.g. <http://example.org/director/3-Woody%20Allen>. The documents yielded by the iterator
do not contain field "type" since it is defined higher in the document hierarchy. To address this issue, we
define an element of class xrr:PushDown with the xrr:pushDown property:

An **xrr:PushDown** instance is defined within an xR2RML logical source by means of the **xrr:pushDown** property. It is valid only as a companion of an rml:iterator property. It specifies a reference (property xrr:reference), written using the reference formulation (section 1.4), whose value must be added in the documents yielded by the iterator as a new data element whose name is given by the **xrr:as** property of the xrr:PushDown instance.

In our example, this should look like:

<#Directors>
xrr:logicalSource [
xrr:query "dbFind( { directors: { $exists: true } } )";
rml:iterator "$.directors.*";
xrr:pushdown [ xrr:reference "$.type" xrr:as "newType" ];
];
rr:subjectMap [
rr:template "http://example.org/director/{$.newType}-{$.name}";
];
rr:predicateObjectMap [
rr:predicate ex:directed;
rr:objectMap [ xrr:reference "$.movies.*" ];
].

As a result, a field "newType" (property xrr:as) is created within the documents yielded by the iterator. The
value of this field is the result of evaluating the "$.type" reference (xrr:reference property) against the
documents fetched from the database. Example:

{ "name": "Wong Kar-wai", "movies": ["2046", "In the Mood for Love"], "newType": 3 }
{ "name": "Woody Allen", "movies": ["Manhattan", "Annie Hall"], "newType": 3 }

Finally, the following triples are produced:
<http://example.org/director/3-Woody%20Allen> ex:directed "Manhattan".

<http://example.org/director/3-Woody%20Allen> ex:directed "Annie Hall".

<http://example.org/director/3-Wong%20Kar-wai> ex:directed "2046".

<http://example.org/director/3-Wong%20Kar-wai> ex:directed "In the Mood for Love".

## 3.2 Creating RDF terms with Term Maps

### 3.2.1 xR2RML Term Maps

R2RML defines a _term map_ as a function that generates _RDF terms_ from a logical table row.

A term map is either a subject map, predicate map, object map or graph map.

A term map must be exactly one of the following types:

* a constant-valued term map (property rr:constant)

* a column-valued term map (property rr:column)

* a template-valued term map (property rr:template).

R2RML treats all values from the input database as literals expressed in built-in data types. To deal with structured values such as collections or key-value associations, xR2RML term maps extend R2RML term maps so that structured values can be parsed, and data elements within structured values can be selected to build RDF terms. xR2RML extensions are described in this section.

#### 3.2.1.1 Constant-, Column-, Reference- and Template-valued Term Maps

R2RML properties rr:column and rr:template reference columns of a logical table. xR2RML not only references columns but also any data element within structured values. xR2RML relies on the **rml:reference**, that extends property rr:column. Its object is a column name (in the case of an RDB, CSV/TSV file, extensible column store, SPARQL result set, etc.), an XPath expression (in the case of XML data) and a JSONPath expression (in the case of JSON data). Furthermore, xR2RML introduces the possibility to reference data elements in data with mixed formats (§3.2.2.2). Thus, xR2RML extends property rml:reference with property **xrr:reference**. This leads to the following definition of an xR2RML term map. xR2RML changes to R2RML are **highlighted**.

A constant-valued term map is represented by a resource that has exactly one rr:constant property. A constant-valued term map always generates the same RDF term.

A column-valued term map has exactly one rr:column property. The value of the rr:column property is a valid column name.

A reference-valued term map has exactly one xrr:reference property. The value of the xrr:reference property is a valid reference to a data element, expressed using the syntax defined by the reference
formulation (section 1.4). A reference-valued term map may have any number of `xrr:pushDown` properties (section 3.2.2.4) if and only if it has an `xrr:nestedTermMap` property.

A template-valued term map has exactly one `rr:template` property. The value of the `rr:template` property is a valid string template. A string template is a format string used to build strings from multiple components. It uses valid references to data elements by enclosing them in curly braces ("{" and "}"). Each reference is expressed using the syntax defined by the reference formulation (section 1.4).

### 3.2.1.2 Term Types of Term Maps

RDF terms generated by a term map have a term type (`rr:termType`) that may be one of the three R2RML term types: `rr:Literal`, `rr:BlankNode` or `rr:IRI`.

xR2RML extends the `rr:termType` property with four new values, hereafter referred to as **RDF collection or container term types**:

- A term map with `xrr:RdfList` as value of property `rr:termType` generates an RDF collection of type `rdf:List`;

- A term map with `xrr:RdfSeq`: as value of property `rr:termType` generates an RDF container of type `rdf:Seq`;

- A term map with `xrr:RdfBag`: as value of property `rr:termType` generates an RDF container of type `rdf:Bag`;

- A term map with `xrr:RdfAlt`: as value of property `rr:termType` generates an RDF container of type `rdf:Alt`.

### 3.2.1.3 Nested Term Maps

Hierarchical data such as JSON or XML documents commonly have more than one level of nesting, resulting in tree-like values that may need to be parsed in depth, e.g. to nest RDF collections and containers (build an RDF collection of RDF collections).

An xR2RML term map may have an `xrr:nestedTermMap` property, whose range is the `xrr:NestedTermMap` class.

In a column-valued or reference-valued term map, the `xrr:nestedTermMap` property describes how to translate values produced by the `rr:column` or `xrr:reference` properties into RDF terms.

In a template-valued term map, the `xrr:nestedTermMap` property describes how to translate values
produced by applying the template string to input values into RDF terms.

In a constant-valued term map, it is invalid to define a nested term map.

A **nested term map** may have the properties below:

- **xrr:reference** bears the same semantics as in the context of a term map. Its object is a valid path expression (possibly a mixed-syntax path, see §3.2.2.2). Evaluation of the path expression is performed against values retrieved by the parent of the nested term map. This parent may be a term map or a nested term map.

- **rr:template** bears the same semantics as in the context of a term map. References enclosed in capturing curly braces are valid path expressions (possibly mixed-syntax paths), they apply to values retrieved in the parent of the nested term map. This parent may be a term map or a nested term map.

- **xrr:nestedTermMap** is used to recursively parse any depth of nested structured values;

- **xrr:pushDown** properties if and only if there exists an xrr:nestedTermMap property (see section 3.2.2.4).

- **rr:termType** bears the same semantics as in the context of a term map;

- **rr:language** bears the same semantics as defined in R2RML;

- **rr:datatype** bears the same semantics as defined in R2RML.

A **simple nested term map** is a nested term map that has no xrr:reference nor rr:template property. A simple nested term map is used to qualify terms of an RDF collection or container generated by its parent term map or nested term map, i.e. assign them an optional term type, data type or language tag.

A **reference-valued nested term map** is a nested term map that has exactly one xrr:reference property.

A **template-valued nested term map** is a nested term map that has exactly one rr:template property.

### xrr:nestedTermMap vs. rr:termType:

A nested term map *N* describes how to translate into RDF terms values produced by its parent *P*, *P* may be a term map or a nested term map.

If *P* has no rr:termType property, it simply returns values produced by *N*, therefore the term type of *P* is that of *N*.

If *P* has an rr:termType property with an RDF collection or container term type as object, then values produced by *N* will be assembled in an RDF collection or container.

Lastly, *P* should not have an rr:termType property with an R2RML term type (literal, blank node, IRI) or in other words, a nested term map cannot be used in the context of a term map or nested term map that has an R2RML term type (literal, IRI, blank node). Thus:
If a term map or nested term map has an `xrr:nestedTermMap` property, then it should have either no `rr:termType` property or an `rr:termType` property with an RDF collection or container term type.

Formally:

?P is an rr:TermMap or xrr:NestedTermMap.

?P xrr:nestedTermMap ?N.

?P rr:termType ?tt.

⇒ ?tt is one of xrr:RdfList, xrr:RdfSeq, xrr:RdfBag or xrr:RdfAlt

A term map or nested term map with an RDF collection or container term type and no `xrr:nestedTermMap` property is assumed to have a **default xrr:nestedTermMap property** defined as follows:

- If the parent term map or nested term map is reference-valued:

xrr:nestedTermMap [ rr:termType rr:Literal ];

- If the parent term map or nested term map is template-valued:

xrr:nestedTermMap [ rr:termType rr:IRI ];

Finally, as defined in R2RML, properties `rr:language` and `rr:datatype` apply when generating literals only:

A term map or nested term map may have an `rr:language` or `rr:datatype` property only if its term type is `rr:Literal` (either stated by property `rr:termType` or inferred as a default value).

Nested term maps are exemplified in section 3.2.3.

## 3.2.2 Referencing data elements

### 3.2.2.1 Referencing simple data elements

The table below exemplifies the use of properties `rr:column`, `xrr:reference` and `rr:template` to reference simple data elements (i.e. with non-mixed data formats) from the logical source.

<table><thead><tr><td>Logical source</td><td>Term map</td></tr></thead><tbody><tr><td>Relational database: either rr:column or xrr:reference can be used to name a column.</td><td>[] rr:column "NAME".<br/>[] xrr:reference "NAME".<br/>[] rr:template "{NAME}".</td></tr><tr><td>Extensible column store: properties xrr:reference and rr:template reference data elements by column names.</td><td>[] xrr:reference "NAME".<br/>[] rr:template "{NAME}".</td></tr></tbody></table>
<table><tr><td>XML database supporting: properties xrr:reference and rr:template reference data elements by XPath expressions.</td><td>[] xrr:reference "/name".<br/>[] rr:template "{//name}".</td></tr><tr><td>NoSQL document store: xrr:reference and rr:template reference data elements using a valid JSONPath expression.</td><td>[] xrr:reference "$.name".<br/>[] rr:template "{$.name}".</td></tr><tr><td>RDF graph store accessed using a SPARQL SELECT query: xrr:reference and rr:template reference data elements by name of variable returned in the SPARQL result set.</td><td>[] xrr:reference "?name".<br/>[] rr:template "{?name}".</td></tr></table>

Remark: If a term map references a structured value but does not parse it using a nested term map, then generated RDF terms are string literals containing a simple serialization of structured values. Example:

<table><tr><td>Input data</td><td>{ "person": { "First_name":"John", "Last_name":"Smith" } }</td></tr><tr><td>Term map</td><td>[] rr:objectMap [ xrr:reference "$.person"; ];</td></tr><tr><td>Generated RDF term</td><td>The structured value matching the JSONPath expression "$.person" is returned as a string literal in quotes: '{ "First_name":"John", "Last_name":"Smith" }'</td></tr></table>

### 3.2.2.2 Referencing data elements with mixed data formats

In some use cases, databases are commonly used to store values written in a data format that they cannot interpret. For instance, an application designer may choose to embed JSON, CSV, or XML values in the cells of a relational table, for performance concerns or application design constraints.

To reference data elements within such mixed contents, xR2RML allows a term map to reference data elements with **mixed-syntax paths**:

Properties `xrr:reference` and `rr:template` may use **mixed-syntax paths** to reference data elements across data in different formats. A mixed-syntax path consists of the concatenation of several path expressions separated by the slash `'/'` character. Each individual path is enclosed in a **syntax path constructor** naming the path syntax explicitly. Existing constructors are:

- `Column(column-name)`: applies to row/column databases such as relational database and extensible column-store.

- `CSV(column-name)`, `TSV(column-name)`: applies to data formatted as comma-separated or tab-separated values. Column-name may be a 0-based column index, or an actual column name if a
head line provides column names.

- **JSONPath(JSONPath-expression):** applies to any data formatted in JSON.

- **XPath(XPath-expression):** applies to any data formatted in XML.

In expressions enclosed in a syntax path constructor, special characters '/' , '(' , ')' , '{' and '}' must be escaped with a '\'. Since, in Turtle syntax, the '\' character itself must be escaped with an additional '\', special characters are escaped with '\\'.

Example:

<table>
   <tr>
    <td>
     Input data
    </td>
    <td>
     Relational table with one column:
     <br/>
     Name
     <br/>
     { "First Name":"John", "Last Name":"Smith" }
    </td>
   </tr>
   <tr>
    <td>
     Logical source definition and Term map
    </td>
    <td>
     [] xrr:logicalSource [ ... ];
     <br/>
     ...
     <br/>
     rr:objectMap [
     <br/>
     xrr:reference "Column(Name)/JSONPath($.First Name)";
     <br/>
     rr:language "en";
     <br/>
     ];
    </td>
   </tr>
   <tr>
    <td>
     Generated RDF term
    </td>
    <td>
     "John"@en
    </td>
   </tr>
  </table>

From the example above, it can be noticed that (i) the leftmost syntax path constructor (Column) is
consistent with the reference formulation (section 1.4), and (ii) data elements referenced by mixed-syntax
path "Column(Name)/JSONPath($.First Name)" are formatted in JSON, corresponding to the rightmost syntax
path constructor. More generally:

The leftmost syntax path constructor of a mixed-syntax path must be consistent with the reference
formulation (section 1.4).

- Constructors Column(), CSV() and TSV() apply with the column name reference formulation,

- Constructor XPath() applies with the XPath reference formulation,

- Constructor JSONPath() applies with the JSONPath reference formulation.

The format of data retrieved by a mixed-syntax path is the format of the rightmost syntax path
constructor.
### 3.2.2.3 Production of multiple RDF terms

In a row-based logical source, a column reference returns exactly one scalar value per triples map iteration step: the value of the cell identified by "column name" in the current row. Thus, an R2RML term map generates zero or one RDF term during each iteration step, ultimately a triples map generates zero or one triple during each iteration step.

Due to the tree-like nature or JSON and XML data formats, JSONPath and XPath expressions allow addressing not only literals but also structured values. Thus, using the `xrr:reference` or `rr:template` properties with a JSONPath or XPath expression may return multiple values during each triples map iteration step. Hence the introduction of the term map iteration.

A term map iteration is a process that occurs in a term map during each triples-map iteration step. Thus, a reference-valued or template-valued term map generates zero to any number of RDF terms during each triples-map iteration step.

Examples:

<table><tr><td>Input data retrieved in one triples-map iteration step</td><td>{ "FirstNames": ["John", "Albert"], "Last Name": "Smith" }</td><td>&lt;person&gt; &lt;FirstNames&gt; &lt;item&gt;John&lt;/item&gt; &lt;item&gt;Albert&lt;/item&gt; &lt;/FirstNames&gt; &lt;Last Name&gt;Smith&lt;/Last Name&gt; &lt;/person&gt;</td></tr><tr><td>Term map</td><td>[] rr:objectMap [ xrr:reference "$.FirstNames.*" ];</td><td>[] rr:objectMap [ xrr:reference "/person/FirstNames/item"; ];</td></tr><tr><td>Generated RDF terms</td><td>"John" "Albert"</td><td>"John" "Albert"</td></tr></table>

The term map iteration applies identically in the context of mixed-syntax paths. Example:

<table><tr><td>Input data</td><td>&lt;person&gt; &lt;name&gt;John Smith&lt;/name&gt; &lt;items&gt;[1,2,3]&lt;/items&gt; &lt;/person&gt; XML element "items" contains a value expressed as a JSON array.</td></tr></table>
<table><tr><td>Term map</td><td><pre>[] xrr:logicalSource [ ... ]
...
rr:objectMap [
    xrr:reference "XPath(\\person\\items)/JSONPath($.*)";
    rr:datatype xsd:integer;
]
</pre><p>The last expression of the mixed-syntax path, "JSONPath($.*)", indicates that (i) value "[1,2,3]" is formatted in JSON syntax, and (ii) it must be parsed as such using the "$.*" JSONPath expression.</p></td></tr><tr><td>Generated RDF terms</td><td>1^^xsd:integer<br>2^^xsd:integer<br>3^^xsd:integer</td></tr></table>

A template-valued term map may reference several data elements from the logical source, captured by curly braces ('{' and '}'). If at least one of the data elements referenced in a template string produces several terms, then the following applies:

A template-valued term map produces RDF terms by performing a Cartesian product between all values produced by all data elements referenced in the template.

Example:

<table><tr><td>Input data</td><td><pre>{
  "FirstNames": ['"John", "Albert"]",
  "LastName": "Smith"
}</pre></td></tr><tr><td>Term map</td><td><pre>[] xrr:logicalSource [ ... ];
rr:subjectMap [
  rr:template "http://example.org/{$.FirstNames.*}/{$.Last_name}";
];</pre></td></tr><tr><td>Generated RDF terms</td><td>The template performs a Cartesian product between "Smith" and ["John", "Albert"], resulting in two terms:
<code>&lt;http://example.org/John/Smith&gt;</code><br>
<code>&lt;http://example.org/Albert/Smith&gt;</code></td></tr></table>

Finally, below we define the behavior of a triples map in which one or several term maps generate multiple RDF terms during a single triples map iteration step:
During each iteration of an xR2RML triples map, triples are generated as the Cartesian product between RDF terms produced by the subject map and each predicate-object map. Predicate-object couples result of the Cartesian product between RDF terms produced by each predicate and object map.

Note that a graph map may also produce multiple terms, in which case triples are produced simultaneously in several target graphs.

**xR2RML vs. RML:** RML makes the restriction that a subject map should return zero or one value during each triples map iteration. In the case of xR2RML, we make no such restriction so that the Cartesian product be possibly applied between multiple subjects, multiple predicate-object couples, and multiple graph IRIs. Besides, RML does not describe how a template with several multi-valued references is processed. xR2RML states that the Cartesian product applies equally in this case, whether the template be used as a subject, predicate, object or graph map.

In the example below, during one triples map iteration step, the subject map produces two RDF terms <http://example.org/company/Dell> and <http://example.org/company/Asus>, while the object map produces two literals "Laptop" and "Desktop". A Cartesian product between the two subjects and the two objects results in the production of four triples:

<table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td>Input data: one row retrieved from a relational table, values are formatted in JSON in column "cos", and XML in column "products"</td><td><table><thead><tr><th>cos</th><th>products</th></tr></thead><tbody><tr><td>[ "Dell", "Asus" ]</td><td>&lt;list&gt;<br/>&lt;product&gt;Laptop&lt;/product&gt;<br/>&lt;product&gt;Desktop&lt;/product&gt;<br/>&lt;/list&gt;</td></tr></tbody></table></td></tr><tr><td>Mapping graph</td><td><pre>[] xrr:logicalSource [ ... ];<br/>rr:subjectMap [<br/>rr:template "http://example.org/{Column(cos)/JSONPath($.*)}";<br/>];<br/>rr:predicateObjectMap [<br/>rr:predicate ex:produces;<br/>rr:objectMap [<br/>xrr:reference "Column.products)/XPath(\/list\*/*)";<br/>];<br/>];</pre></td></tr></tbody></table>
<table><tr><td rowspan="4">Generated triples</td><td>&lt;http://example.org/Dell&gt; ex:produces "Laptop".</td></tr><tr><td>&lt;http://example.org/Dell&gt; ex:produces "Desktop".</td></tr><tr><td>&lt;http://example.org/Asus&gt; ex:produces "Laptop".</td></tr><tr><td>&lt;http://example.org/Asus&gt; ex:produces "Desktop".</td></tr></table>

### 3.2.2.4 Pushing down data elements during a term map iteration

As seen in the previous section, a **term map iteration** may occur in the context of hierarchical data formats. Within a term map iteration, it may be needed to access data elements higher in the hierarchical documents, such as JSON fields that are outside of the iteration and thus no longer available. To deal with such cases, a **reference-valued term map** or a **reference-valued nested term map** may have any number of `xrr:pushDown` properties, whose semantics is that defined in the context of a logical source (section 3.1.3).

Example:

<table><tr><td>Input data</td><td><pre>{ "id": 5,
  "FirstNames": ['"John", "Albert"]',
  "Last Name": "Smith"
}</pre></td></tr><tr><td>Term map</td><td><pre>rr:objectMap [ 
  rr:reference "$.FirstNames"; 
  xrr:pushDown [ xrr:reference "$.id"; xrr:as "personId" ]; 
  xrr:nestedTermMap [ 
    rr:template "Person {$.$.personId}: {$.*}"; 
    rr:termType xrr:Literal; 
  ] 
];</pre></td></tr><tr><td>Generated RDF terms</td><td><pre>"Person 5: John"
"Person 5: Albert"</pre></td></tr></table>

### 3.2.2.5 Production of RDF collections or containers

A term map with an RDF collection or container term type generates one RDF term during each triples map iteration step. The elements of the collection or container are the RDF terms produced by the term map, whether using property `rr:column`, `xrr:reference` or `rr:template`.

In the example below, the triples map generates one triple per iteration step, the object of this triple is an RDF bag (itself consisting of several triples):

<table><tr><td>Input data: JSON</td><td>&lt;company "name"="Dell"&gt;</td></tr></table>
<table><tr><td>document retrieved in a single iteration step</td><td>&lt;products&gt;<br/>&lt;product&gt;Laptop&lt;/product&gt;<br/>&lt;product&gt;Desktop&lt;/product&gt;<br/>&lt;/products&gt;<br/>&lt;/company&gt;</td></tr><tr><td>Mapping graph</td><td>[] xrr:logicalSource [ ... ];<br/>rr:subjectMap [<br/>rr:template "http://example.org/{/company/@name}";<br/>];<br/>rr:predicateObjectMap [<br/>rr:predicate ex:builds;<br/>rr:objectMap [<br/>xrr:reference "/company/products/*";<br/>rr:termType xrr:RdfBag;<br/>];<br/>];</td></tr><tr><td>Generated triples</td><td>&lt;http://example.org/Dell&gt; ex:builds [<br/>a rdf:Bag;<br/>rdf:_1 "Laptop";<br/>rdf:_2 "Desktop" .<br/>].</td></tr></table>

Unlike RDF terms of type IRI or blank node, RDF terms of type RDF collection or container cannot be used as subject or predicate of an RDF triple, nor as a graph IRI. Consequently:

A term map with term type `xrr:RdfList`, `xrr:RdfSeq`, `xrr:RdfBag` or `xrr:RdfAlt` is an object map (hence it cannot be a subject map, predicate map nor graph map).

Formally:

`?X an rr:TermMap.`

`?X rr:termType ?tt.`

`?tt is one of xrr:RdfList, xrr:RdfSeq, xrr:RdfBag or xrr:RdfAlt`

`⇒ ?X an rr:ObjectMap.`

A nested term map (property `xrr:nestedTermMap`) can be used to specify a term type, language tag or data type of members of an RDF collection or container. The example below illustrates the usage of a nested term map to generate an RDF collection of IRIs (first example), and an RDF sequence of data-typed literals (second example):
<table><tr><td>Input data</td><td>{ "key1": ["url1", "url2"] }</td><td>{ "key1": [10, 20] }</td></tr><tr><td>Term map</td><td>[] rr:objectMap [ xrr:reference "$.key1.*"; rr:termType xrr:RdfList; xrr:nestedTermMap [ rr:termType rr:IRI; ]; ];]</td><td>[] rr:objectMap [ xrr:reference "$.key1.*"; rr:termType xrr:RdfSeq; xrr:nestedTermMap [ rr:termType rr:Literal; rr:datatype xsd:integer; ]; ];]</td></tr><tr><td>Generated RDF terms</td><td>In Turtle abbreviated notation: (&lt;url1&gt; &lt;url2&gt;)</td><td>[ a rdf:Seq; rdf:_1 10^^xsd:integer; rdf:_2 20^^xsd:integer. ];]</td></tr></table>

In a template-valued term map, the `xrr:nestedTermMap` property applies to values resulting from the application of the template string to the input values. In the first example below, term type `rr:IRI` applies to the result of the template string. The same principle applies in the second example with term type `rr:Literal` and `datatype xsd string`.

<table><tr><td>Input data</td><td>{ "FirstNames": ['John", "Albert"]', "Last Name": "Smith" }</td><td>{ "FirstNames": ['John", "Albert"]', "Last Name": "Smith" }</td></tr><tr><td>Term map</td><td>[] rr:objectMap [ rr:template "http://example.org/ {$.$FirstNames.*}/{$.Last Name}"; rr:termType xrr:RdfList; xrr:nestedTermMap [ rr:termType rr:IRI; ]; ];]</td><td>[] rr:objectMap [ rr:template "{$.$FirstNames.*}{$.$Last Name}"; rr:termType xrr:RdfList; xrr:nestedTermMap [ rr:termType rr:Literal; rr:datatype xsd: string; ]; ];]</td></tr><tr><td>Generated RDF terms</td><td>(&lt;http://example.org/John/Smith&gt; &lt;http://example.org/Albert/Smith&gt;)</td><td>( "John Smith"^^xsd: string "Albert Smith"^^xsd: string )</td></tr></table>
### 3.2.3 Parsing nested structured values

The example below illustrates the use of a nested term map to (i) parse nested structured values ("teams" are collections of "team" elements, which are collections of "member" elements) and (ii) translate those nested structured values into RDF terms of class `rdf:List`.

<table><tr><td>Input data</td><td>< teams > < team > < member > John </ member > < member > Paul </ member > </ team > < team > < member > Cathy </ member > < member > Ed </ member > </ team > </ teams></td></tr><tr><td>Term map</td><td>< ] ] rr:objectMap [ xrr:reference "/teams/team"; xrr:nestedTermMap [ xrr:reference "/member"; rr:termType xrr:RdfList; ]; ];</td></tr><tr><td>Generated RDF terms</td><td>The first xrr:reference property ("/teams/team") selects "team" elements from the XML input, each "team" element being the root of an XML tree whose descendants are "member" elements.<br/>The second xrr:reference property ("/member"), within the xrr:nestedTermMap property, is evaluated sequentially against the results of the parent reference expression. Thus, the xrr:RdfList term type successively applies to "member" elements of the first team, then to "member" elements of the second team. Finally the term map generates two RDF collections, one per team element.<br/><br/>Note: the object map has no rr:termType property, therefore its term type is that of its nested term type, that is xrr:RdfList.</td></tr></table>
The subsequent example generates one RDF sequence of nested RDF collections. Elements of the inner RDF collections are typed as `rr:Literal` and assigned a language tag using a second nested `xrr:nestedTermMap` property.

<table><tr><td>Input data</td><td>{ "teams": [ ["John", "Paul"], ["Cathy", "Ed"] ] }</td></tr><tr><td>Term map</td><td>[] rr:objectMap [ xrr:reference "$.teams.*"; rr:termType xrr:RdfSeq; # represent "teams" as an rdf:Seq # Describe the elements of the RDF sequence xrr:nestedTermMap [ rr:template "Player {$.*}"; rr:termType xrr:RdfList; # represent each team as an rdf:List # Type members of each team as literals with language "en" # using a simple nested term map xrr:nestedTermMap [ rr:termType rr:Literal; rr:language "en" ]; ]; ];</td></tr><tr><td>Generated RDF terms</td><td>[ a rdf:Seq; rdf:_1 ("Player John"@en "Player Paul"@en); rdf:_2 ("Player Cathy"@en "Player Ed"@en); ]</td></tr></table>

As already mentioned, in a template-valued term map, property `xrr:nestedTermMap` applies to values resulting from the application of the template string to input values. Thus, defining a nested term map in a template-valued term map suggests that the template produces a valid expression with regards to the current data format, that, in turn, is interpreted against a path expression provided by an `xrr:reference` or `rr:template` property.

For instance, applying the template string:

"{"first":{"FirstNames}},{"last": "{"LastName}"} \}"

would produce a string formatted as a JSON dictionary, like:

{ "first": "John", "last": "Smith" }

This use case is illustrated in the example below:
<table><tr><td>Input data</td><td><pre>{
  "FirstNames": ['"John", "Albert"]",
  "Last Name": "Smith"
}</pre></td></tr><tr><td>Term map</td><td><pre>[] rr:objectMap [
  rr:template '{"first": "${.FirstNames.*}", "last": "${.Last Name}" }';
  xrr:nestedTermMap [
    xrr:reference "$.*";
    rr:termType xrr:RdfList;
  ];
]</pre></td></tr><tr><td>Generated RDF terms</td><td><pre>( "John" "Smith" )
( "Albert" "Smith" )

Two values are generated by applying the template string, those values are formatted as JSON arrays:
{ "first": "John", "last": "Smith" }
{ "first": "Albert", "last": "Smith" }

The xrr:nestedTermMap property instructs to parse those values using the JSONPath expression "$.*" (property xrr:reference), and generates an RDF collection (rdf:List) for each of them.</pre></td></tr></table>

**Note:** this use case may seem rather awkward and probably of little use, but insofar as it is consistent with the xR2RML language definition, we think it should be considered as valid.

### 3.2.4 Multiple Mapping Strategies

The flexibility offered by nested term maps allows the same mapping to be written using various strategies: path expressions of properties `xrr:reference` and `rr:template` can be split in several levels of term map and nested term map.

For instance, both term maps below produce equivalent results. In the first case (left), the JSONPath expression (`$.teams.*`) retrieves all team members at once. In the second case (right), teams are retrieved first (`$.teams.*`), then the `xrr:nestedTermMap` property runs a second JSONPath evaluation to retrieve and datatype team members.

<table><tr><td>Input data</td><td><pre>{ "teams": [ ["John", "Paul"],
  ["Cathy", "Ed"] ] }</pre></td></tr></table>
<table><tr><td>Term maps</td><td><pre>[] xrr:logicalSource [ ... ];
    rr:objectMap [
        xrr:reference "$.teams.*.*";
        rr:datatype xsd:string;
    ];</pre></td><td><pre>[] xrr:logicalSource [ ... ];
    rr:objectMap [
        xrr:reference "$.teams.*";
        xrr:nestedTermMap [
            xrr:reference "$.*";
            rr:datatype xsd:string;
        ];
    ];</pre></td></tr><tr><td>Generated<br/>RDF terms</td><td><pre>"John"^^xsd:string
"Paul"^^xsd:string
"Cathy"^^xsd:string
"Ed"^^xsd:string</pre></td><td></td></tr></table>

It is likely that the first case will be more efficient as only one JSONPath evaluation is performed, whereas in the second case two JSONPath evaluations are performed in sequence.

Similarly, the example below shows how a mixed-syntax path can be split into a term map and a nested term map:

<table><tr><td><pre>[] xrr:logicalSource [ ... ];
    rr:objectMap [
        xrr:reference
        "Column(col)/XPath(\\person\\name)";
        rr:datatype xsd:string;
    ];</pre></td><td><pre>[] xrr:logicalSource [ ... ];
    rr:objectMap [
        rr:column "col";
        xrr:nestedTermMap [
            xrr:reference "XPath(\\person\\name)";
            rr:datatype xsd:string;
        ];
    ];</pre></td></tr></table>

Both mappings are likely to be equally efficient, as both evaluations (column selection and XPath expression evaluation) need to be done anyway.

### 3.2.5 Default Term Types

This section is an adaptation of section 7.4 (http://www.w3.org/TR/r2rml/#termtype) of the R2RML specification. xR2RML additions to R2RML are highlighted.

If the term map has an optional `rr:termType` property then its term type is the value of that property. The value MUST be one of the following options:

- If the term map is a subject map: `rr:IRI` or `rr:BlankNode`

- If the term map is a predicate map: `rr:IRI`
- If the term map is an object map: `rr:IRI`, `rr:BlankNode`, `rr:Literal`, `rdf:List`, `rdf:Seq`, `rdf:Bag`, `rdf:Alt`.

- If the term map is a graph map: `rr:IRI`.

If the term map does not have an `rr:termType` property, then its term type is:

- `rr:Literal`, if it is an object map and at least one of the following conditions is true:

- It is a column-based term map.

- It has an `rr:language` property (and thus a specified language tag).

- It has an `rr:datatype` property (and thus a specified datatype).

- It does not have an `rr:language` property and it has a nested term map that has an `rr:language` property.

- It does not have an `rr:datatype` property and it has a nested term map that has an `rr:datatype` property.

- the term type of the value of its nested term map.

- `rr:IRI`, otherwise.

A corollary of this definition is that the `xrr:nestedTermMap` property may be used in a subject map, predicate map or graph map only if it produces IRIs. Consequently:

A term map with an `xrr:nestedTermMap` property may be a subject map or graph map only if (i) it does not have an `rr:termType` property and (ii) its nested term map has an `rr:termType` property with object `rr:IRI` or `rr:BlankNode`.

A term map with an `xrr:nestedTermMap` property may be a predicate map only if (i) it does not have an `rr:termType` property and (ii) its nested term map property has an `rr:termType` property with object `rr:IRI`.

## 3.3 Reference relationships between logical sources

The following definitions are an adaptation of R2RML specification section 8 (http://www.w3.org/TR/r2rml/#foreign-key). xR2RML additions to R2RML are highlighted.

A referencing object map allows using the subjects of another triples map as the objects generated by a predicate-object map. Since both triples maps may be based on different logical sources, this may require a join between the logical sources.

A referencing object map resource has exactly one `rr:parentTriplesMap` property (its value is a triples map), and optional `rr:joinCondition` properties. A join condition has exactly one `rr:child` property and one `rr:parent` property. The `rr:child` property references the join condition's child data element, the `rr:parent` property references the join condition's parent data element. Data element references are valid path expressions with regards to the reference formulation (section 1.4), possibly using mixed-
syntax paths.

A referencing object map may have an rr:termType property with an RDF collection or container term type (see further details in §3.3.2).

The child query of a referencing object map is the query or source name of the logical source of the triples map containing the referencing object map.

The parent query of a referencing object map is the query or source name of the logical source of the referencing object map's parent triples map.

Properties rr:child and rr:parent use valid path expressions to reference data elements. As described in §3.2.2.3, such path expressions may produce multiple terms. Consequently, the equivalent joint query of a referencing object map must take into account the fact that child and parent references be multi-valued. More precisely, a join between two multi-valued references should be satisfied if at least one data element of the first reference matches one data element of the second reference.

The joint query of a referencing object map is defined below using SQL syntax (SELECT... FROM... AS... WHERE) and first order logic for the description of WHERE conditions:

If a referencing object map has no join condition, its joint query is:

SELECT * FROM ({child-query}) AS tmp

If a referencing object map has at least one join condition, its joint query is:

SELECT * FROM ({child-query}) AS child, ({parent-query}) AS parent
WHERE ∃ c₁ ∈ eval(child, {child-ref₁}), ∃ p₁ ∈ eval(parent, {parent-ref1}), c₁ = p₁
AND ∃ c₂ ∈ eval(child, {child-ref₂}), ∃ p₂ ∈ eval(parent, {parent-ref2}), c₂ = p₂
AND ...

where {child-ref*n*} and {parent-ref*n*} are the child reference and parent reference of the n^th^ join condition, and eval(source, {ref}) is the result of the evaluation of expression "{ref}" on data "source".

Note: when applied to a relational database, in which child and parent references are single-valued, this definition can be simplified into the R2RML joint query definition:

SELECT * FROM ({child-query}) AS child, ({parent-query}) AS parent
WHERE child.{child-ref1} = parent.{parent-ref1}
AND child.{child-ref2} = parent.{parent-ref2}
AND ...
If a referencing object map has no `rr:termType` property, then its term type is `rr:IRI` (compliant with the R2RML definition).

A referencing object map may have an `rr:termType` property with an RDF collection or container term type (`xrr:RdfList`, `xrr:RdfSeq`, `xrr:RdfBag` or `xrr:RdfAlt`). In that case, members of the collection or container are necessarily of type `rr:IRI`.

In a referencing object map with an RDF collection or container term type, results of the joint query pertaining to the same subject term are grouped together. The objects of the triples map are grouped in a single object of type RDF collection or container, as instructed by the `rr:termType` property.

In the example below the referencing object map has an `rr:termType` property with value `xrr:RdfList`:

<table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td>Input data</td><td>JSON documents retrieved by the query in the &lt;#Study&gt; triples map:<br> { "study_id":1, "study_name":"study1" }<br> { "study_id":2, "study_name":"study2" }<br> { "study_id":3, "study_name":"study3" }<br><br> JSON documents retrieved by the query in the &lt;#Doctor&gt; triples map:<br> { "doc_name":"D1", "studies": [1,2] }<br> { "doc_name":"D2", "studies": [2,3] }</td></tr><tr><td>Mapping graph</td><td>Below, queries to retrieve Studies and Doctors are referred to as &lt;Study query&gt; and &lt;Doctor query&gt;.<br><br> &lt;#Doctor&gt;<br> xrr:logicalSource [ xrr:query "&lt;Doctor query&gt;" ];<br> rr:subjectMap [<br> rr:template "http://example.org/doc/{$.doc_name}";<br> ].<br><br> &lt;#Study&gt;<br> xrr:logicalSource [ xrr:query "&lt;Study query&gt;" ];<br> rr:subjectMap [<br> rr:template "http://example.org/study/{$.study_name}";<br> ];<br> rr:predicateObjectMap [<br> rr:predicate ex:hasInvestigators;<br> rr:objectMap [<br> rr:parentTriplesMap &lt;#Doctor&gt;;</td></tr></tbody></table>
rr:joinCondition [
    rr:child "$.study_id";
    rr:parent "$.studies.*";
];

rr:termType xrr:RdfList;
];
].

Generated RDF triples

<http://example.org/study/study1> ex:hasInvestigators
( <http://example.org/doc/D1> ).

<http://example.org/study/study2> ex:hasInvestigators
( <http://example.org/doc/D1>
<http://example.org/doc/D2> ).

<http://example.org/study/study3> ex:hasInvestigators
( <http://example.org/doc/D2> ).

Explanation: according to the equivalent joint query definition, the joint query is as
follows:

SELECT * FROM (<Study query>) as child,
(<Doctor query>) as parent
WHERE ∃ p ∈ eval(parent, $.studies.*),
p = eval(child, $.study_id)

where eval(parent, $.studies.*) represents the evaluation of path "$.studies.*" on the
result of the parent query, and eval(child, $.study_id) represents the evaluation of path
"$.study_id" on the result of the child query.

The equivalent joint query results in the following documents:

{ "study_id":1, "study_name":"study1", "doc_name":"D1", "studies": [1,2] }
{ "study_id":2, "study_name":"study2", "doc_name":"D1", "studies": [1,2] }
{ "study_id":2, "study_name":"study2", "doc_name":"D2", "studies": [2,3] }
{ "study_id":3, "study_name":"study3", "doc_name":"D2", "studies": [2,3] }

Then, term type xrr:RdfList instructs to group results pertaining to the same subject, i.e. by
"study_id".
### 3.3.3 Generating RDF collection/container with a referencing object map in the relational case

An interesting consequence of using the `rr:termType` in a referencing object map is the ability, in the case of a relational database with standard SQL values, to build an RDF collection or container reflecting a one-to-many relation. In the example below, foreign key `Study.doctor` relates each study to its investigator in a many-to-one relation (several studies may have the same investigator). Considered the other way round, it can be seen as a one-to-many relation (one doctor investigates several studies). The mapping graph describes the generation of each doctor along with the list of studies he/she investigates.

<table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td>Input data</td><td><table><thead><tr><th colspan="3">Table Study</th></tr><tr><th>study_id</th><th>study_name</th><th>doctor</th></tr></thead><tbody><tr><td>1</td><td>study1</td><td>1</td></tr><tr><td>2</td><td>study2</td><td>1</td></tr><tr><td>3</td><td>study3</td><td>2</td></tr></tbody></table><table><thead><tr><th colspan="2">Table Doctor</th></tr><tr><th>doc_id</th><th>doc_name</th></tr></thead><tbody><tr><td>1</td><td>D1</td></tr><tr><td>2</td><td>D2</td></tr></tbody></table></td></tr><tr><td>Mapping graph</td><td><pre><code>&lt;#Study&gt;<br>    rr:logicalTable [ rr:tableName "Study" ];<br>    rr:subjectMap [<br>        rr:template "http://example.org/study/{study_name}";<br>    ].<br><code>&lt;#Doctor&gt;<br>    rr:logicalTable [ rr:tableName "Doctor" ];<br>    rr:subjectMap [<br>        rr:template "http://example.org/doc/{doc_name}";<br>    ].<br>    rr:predicateObjectMap [<br>        rr:predicate ex:investigatesStudies;<br>        rr:objectMap [<br>            rr:parentTriplesMap &lt;#Study&gt;;<br>            rr:joinCondition [<br>                rr:child "doc_id";<br>                rr:parent "doctor;
</code></pre></td></tr></tbody></table>
<table><tr><td></td><td>];<br/>rr:termType xrr:RdfList;<br/>];<br/>].</td></tr><tr><td>Generated RDF triples</td><td>&lt;http://example.org/doc/D1&gt; ex: investigatesStudies<br/>(&lt;http://example.org/study/study1&gt;<br/>&lt;http://example.org/study/study2&gt;).<br/>&lt;http://example.org/doc/D2&gt; ex: investigatesStudies<br/>(&lt;http://example.org/study/study3&gt;).<br/><br/>The equivalent joint query results in this table:<table><thead><tr><td>doc_id</td><td>doc_name</td><td>study_id</td><td>study_name</td><td>doctor</td></tr></thead><tbody><tr><td>1</td><td>D1</td><td>1</td><td>study1</td><td>1</td></tr><tr><td>1</td><td>D1</td><td>2</td><td>study2</td><td>1</td></tr><tr><td>2</td><td>D2</td><td>3</td><td>study3</td><td>2</td></tr></tbody></table>Results are grouped by subjet, i.e. by column "doc_name" to generate RDF lists.</td></tr></table>
4 References

[1] S. Das, S. Sundara, R. Cyganiak, R2RML: RDB to RDF Mapping Language, (2012).

[2] A. Dimou, M.V. Sande, RDF Mapping Language (RML) Unofficial Draft 17 September 2014, (2014).

[3] A. Dimou, M. Vander Sande, P. Colpaert, E. Mannens, R. Van de Walle, Extending R2RML to a source-
independent mapping language for RDF, in: Workshop Proceedings, 12th International Semantic Web
Conference Posters & Demos, Sydney, Australia, 2013: pp. 237–240.

[4] A. Dimou, M. Vander Sande, P. Colpaert, R. Verborgh, E. Mannens, R. Van de Walle, RML: A Generic Language for Integrated RDF Mappings of Heterogeneous Data, in: Proceedings of the 7th Workshop on Linked Data on the Web (LDOW2014), Seoul, Korea, 2014.

[5] S.K. Gajendran, A Survey on NoSQL Databases (technical report), 2013.

[6] R. Hecht, S. Jablonski, NoSQL Evaluation: A Use Case Oriented Survey, in: Proceedings of the 2011 International Conference on Cloud and Service Computing, IEEE Computer Society, Washington, DC, USA, 2011: pp. 336–341.

[7] B. Kolev, P. Valduriez, R. Jimenez-Peris, N. Martínez-Bazan, J. Pereira, CloudMdsQL: Querying Heterogeneous Cloud Data Stores with a Common Language.pdf, in: Proceeding of the BDA 2014 Conference, Autrans, France, 2014.

[8] K.W. Ong, Y. Papakonstantinou, R. Vernoux, The SQL++ Unifying Semi-structured Query Language, and an Expressiveness Benchmark of SQL-on-Hadoop, NoSQL and NewSQL Databases (submitted), CoRR. abs/1405.3631 (2014).