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, 23.01.2017, Automatic Mappings of Tables to Knowledge Graphs and Open Table Extraction ( 2017-01-20T14:02:35+01:00 by Ivan Ermilov)

2017-01-20T14:02:35+01:00 by Ivan Ermilov

Automatic Mappings of Tables to Knowledge Graphs and Open Table Extraction On the upcoming colloquium on 23.01. Read more about "AKSW Colloquium, 23.01.2017, Automatic Mappings of Tables to Knowledge Graphs and Open Table Extraction"

PRESS RELEASE: “HOBBIT so far.” is now available ( 2017-01-09T14:22:29+01:00 by Sandra Bartsch)

2017-01-09T14:22:29+01:00 by Sandra Bartsch

The latest release informs about the conferences our team attended in 2016 as well as about the published blogposts. Read more about "PRESS RELEASE: “HOBBIT so far.” is now available"

4th Big Data Europe Plenary at Leipzig University ( 2016-12-16T14:33:41+01:00 by Sandra Bartsch)

2016-12-16T14:33:41+01:00 by Sandra Bartsch

The meeting, hosted by our partner InfAI e. V., took place on the 14th to the 15th of December at the University of Leipzig. Read more about "4th Big Data Europe Plenary at Leipzig University"

SANSA 0.1 (Semantic Analytics Stack) Released ( 2016-12-09T15:41:04+01:00 by Dr. Jens Lehmann)

2016-12-09T15:41:04+01:00 by Dr. Jens Lehmann

Dear all, The Smart Data Analytics group /AKSW are very happy to announce SANSA 0.1 – the initial release of the Scalable Semantic Analytics Stack. Read more about "SANSA 0.1 (Semantic Analytics Stack) Released"

AKSW wins award for Best Resources Paper at ISWC 2016 in Japan ( 2016-12-09T15:05:00+01:00 by Sandra Bartsch)

2016-12-09T15:05:00+01:00 by Sandra Bartsch

Our paper, “LODStats: The Data Web Census Dataset”, won the award for Best Resources Paper at the recent conference in Kobe/Japan, which was the premier international forum for Semantic Web and Linked Data Community. Read more about "AKSW wins award for Best Resources Paper at ISWC 2016 in Japan"