R2D2: PHP implementation of the D2RQ Mapping Language

The Semantic Web aims at giving data more structure and computer understandable meaning. For that RDF enables to add metadata to the unmanageable mass of data in the World Wide Web. Hence, the transformation of data located in relational databases to RDF plays an essential role. To provide such functionality our implementation R2D2 maps an RDF query to a legacy relational database without having to replicate the data.

R2D2 is be implemented in PHP and uses the RDF API for PHP (RAP) for querying a virtual R2D2-Graph. An R2D2-Graph is read only and may be used like other models in RAP by instantiating a new model named R2D2model. An R2D2model rewrites find(spo) and sparql() queries to SQL queries and transforms the SQL result set back into RDF triples. A database schema is mapped by the D2RQ Mapping Language – a declarative mapping language for describing the relation between an ontology and an relational data model.

R2D2 supports:

  • querying a non-RDF database using SPARQL or find(spo).
  • publishing the content of a non-RDF database in RDF using the RAP NetAPI.
  • automatic generation of a mapping file for any database so you can query it in RDF

Detailed information:

  • R2D2 user manual (soon here – see below for a simple example)
  • Benchmark results in comparison to the RAP database backend (soon here)
  • R2D2 PHPDocs (soon here)
  • D2RQ Language Specification for creating a mapping file

Download

The current version is available at Sourceforge-CVS, click here.

History

Version Comment Date
V0.1 first version of R2D2 01.10.2006

R2D2 Developers

  • Christian Lehmann (Mail: Lehmann.Christian@gmx.net)

Thanks to

  • Sebastian Dietzold for his great ideas and support
  • Sören Auer for making all this possible
  • the D2RQ Developers for the base implementation and the D2RQ Mapping language
  • the RAP Developers for the API

Installation and Use

R2D2 is a RAP Plug In. So first, you need to download RAP. For installing R2D2 you simple have to copy the R2D2 directory into the main RAP folder.

Some example scipts are stored in folder testR2D2. You can copy this folder into the main RAP folder, too. After this you can use them with your mapping files . To include R2D2 you have to add the class R2D2Model (in R2D2/R2D2Model.php) into RAP. After this you are able to create a new virtual RDF-graph by $model = new R2D2Model($mapFile).

A map is represented as an RDF-graph. So if you want the RAP database to manage your map you can copy a map to RAP by RAP-methods. Maps that are stored in RAP are used my $model = new R2D2DbModel($db,$modelName).

For more information check the manual (coming soon).

Example

This short examle script shows how user information in a WordPress is mapped to the FOAF vocabulary.

  • Mapping file: file:wordpressd2rq.n3
  • Database dump: file:wordpressMySQL.sql (My SQL database)
  • foaf vocabulary: foaf-specification
  • find(spo) results of different queries against the database: Test Find.txt
  • SPARQL results of queries against the database: Test RDQL.txt

Example Query: Find all user names

<?php

// Include RAP and r2d2
define('RDFAPI_INCLUDE_DIR', './../api/');
define('R2D2_INCLUDE_DIR', './../R2D2/');
include(RDFAPI_INCLUDE_DIR . 'RdfAPI.php');
include(R2D2_INCLUDE_DIR . 'R2D2Model.php');

// create a new R2D2 model
$model = new R2D2Model('wordpress-d2rq.n3');
$model->enableDebug();

$s = null;
$p = new Resource('http://xmlns.com/foaf/0.1/name');
$o = null;

$result = find($s,$p,$o);

// the same in SPARQL

$sparqlQuery = "PREFIX foaf: <http://xmlns.com/foaf/0.1></http:>
SELECT DISTINCT ?resource ?name WHERE {
?resource foaf:name ?name .
} ORDER BY ?name";

$result = $R2D2Model->sparqlQuery($sparqlQuery);
SparqlEngine::writeQueryResultAsHtmlTable($result);
?>

Using these parts of the D2RQ map

:CMUser rdf:type d2rq:ClassMap;                      
        d2rq:class foaf:Person;
        d2rq:uriPattern "//data#user@@wp_users.ID@@";
        d2rq:dataStorage :database;
        .

:UserDisplayName rdf:type d2rq:DatatypePropertyBridge;
         d2rq:property foaf:name;
        d2rq:column "wp_users.display_name";
        d2rq:belongsToClassMap :CMUser;
.

both find and sparql query will be translated into following SQL command:

SELECT wp_users.ID, wp_users.display_name FROM wp_users

the result set may contain following lines:

wp_users.ID wp_users.display_name
1001 Christian Lehmann
1002 Bob Wheeler

and is translated into the RDF result triple:

Subject //data#user1001
Predicate http://xmlns.com/foaf/0.1/name
Object Christian Lehmann
Subject //data#user1002
Predicate http://xmlns.com/foaf/0.1/name
Object Bob Wheeler

Known Issues

R2D2 implements a new SPARQL2SQL rewriter. This feature is still in progress and buggy. Up to now only group patterns are supported! (for more information see the SPARQL complexity catalog (german version) Regular expressions in find(spo) or SPARQL are not yet supported.

Project Team

News

AKSW Colloquium, 15th August, 3pm, RDF query relaxation ( 2016-08-10T11:03:58+02:00 Michael Roeder)

2016-08-10T11:03:58+02:00 Michael Roeder

On the 15th of August at 3 PM, Michael Röder will present the paper “RDF Query Relaxation Strategies Based on Failure Causes” of Fokou et al. in P702. Read more about "AKSW Colloquium, 15th August, 3pm, RDF query relaxation"

Article accepted in Journal of Web Semantics ( 2016-08-02T09:54:24+02:00 by Lorenz Bühmann)

2016-08-02T09:54:24+02:00 by Lorenz Bühmann

We are happy to announce that the article “DL-Learner – A Framework for Inductive Learning on the Semantic Web” by Lorenz Bühmann, Jens Lehmann and Patrick Westphal was accepted for publication in the Journal of Web Semantics: Science, Services and Agents on … Continue reading → Read more about "Article accepted in Journal of Web Semantics"

AKSW Colloquium, 18.07.2016, AEGLE and node2vec ( 2016-07-18T14:56:44+02:00 TommasoSoru)

2016-07-18T14:56:44+02:00 TommasoSoru

On Monday 18.07.2016, Kleanthi Georgala will give her Colloquium presentation for her paper “An Efficient Approach for the Generation of Allen Relations”, that was accepted at the European Conference on Artificial Intelligence (ECAI) 2016. Read more about "AKSW Colloquium, 18.07.2016, AEGLE and node2vec"

AKSW Colloquium, 04.07.2016. Big Data, Code Quality. ( 2016-06-29T12:34:35+02:00 by Ivan Ermilov)

2016-06-29T12:34:35+02:00 by Ivan Ermilov

On the upcoming Monday (04.07.2016), AKSW group will discuss topics related to Semantic Web and Big Data as well as programming languages and code quality. Read more about "AKSW Colloquium, 04.07.2016. Big Data, Code Quality."

Accepted Papers of AKSW Members @ Semantics 2016 ( 2016-06-27T12:50:01+02:00 by Sandra Bartsch)

2016-06-27T12:50:01+02:00 by Sandra Bartsch

This year’s SEMANTiCS conference which is taking place between September 12 – 15, 2016 in Leipzig recently invited for the submission of research papers on semantic technologies. Read more about "Accepted Papers of AKSW Members @ Semantics 2016"