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, 09.05.2016: Hebrew MMoOn inventory, federated SPARQL query processing ( 2016-05-03T13:57:03+02:00 by Bettina Klimek)

2016-05-03T13:57:03+02:00 by Bettina Klimek

In this week’s colloquium Bettina Klimek will give a practice talk of the paper ‘Creating Linked Data Morphological Language Resources with MMoOn – The Hebrew Morpheme Inventory‘, which she will present at the LREC conference 2016, 23-28 May 2016, Slovenia, … Continue reading → Read more about "AKSW Colloquium, 09.05.2016: Hebrew MMoOn inventory, federated SPARQL query processing"

AKSW Colloquium, 25.04.2016, DISPONTE, Workbench for Big Data Dev ( 2016-04-22T16:05:08+02:00 by Mohamed Sherif)

2016-04-22T16:05:08+02:00 by Mohamed Sherif

In this colloquium, Frank Nietzsche will present his master thesis titled “Game Theory- distributed solving” Game theory analyzes the behavior of individuals in complex situations. One popular game in Europe and North America with such a complex situation is Skat. Read more about "AKSW Colloquium, 25.04.2016, DISPONTE, Workbench for Big Data Dev"

AKSW Colloquium, 18.04.2016, DISPONTE, Workbench for Big Data Dev ( 2016-04-18T10:17:10+02:00 by Patrick Westphal)

2016-04-18T10:17:10+02:00 by Patrick Westphal

In this week’s Colloquium, today 18th of April at 3 PM, Patrick Westphal will present the paper ‘Probabilistic Description Logics under the Distribution Semantics‘ by Riguzzi et. al. Abstract Representing uncertain information is crucial for modeling real world domains. Read more about "AKSW Colloquium, 18.04.2016, DISPONTE, Workbench for Big Data Dev"

AKSW Colloquium, 11.04.2016, METEOR with DBnary ( 2016-04-11T09:07:18+02:00 by Ricardo Usbeck)

2016-04-11T09:07:18+02:00 by Ricardo Usbeck

In this week’s Colloquium, today 11th of April at 3 PM, Diego Moussallem will present the paper by Zied Elloumi et al. titled “METEOR for Multiple Target Languages using DBnary.” [PDF]. Read more about "AKSW Colloquium, 11.04.2016, METEOR with DBnary"

AKSW Colloquium, 04.04.2016, AMIE + Structured Feedback ( 2016-04-04T13:51:45+02:00 by Lorenz Bühmann)

2016-04-04T13:51:45+02:00 by Lorenz Bühmann

In this week’s Colloquium, today 4th of April at 3 PM, Lorenz Bühmann will present the paper by Galárraga et al. titled “AMIE: Association Rule Mining under Incomplete Evidence in Ontological Knowledge Bases.” [PDF]. Read more about "AKSW Colloquium, 04.04.2016, AMIE + Structured Feedback"