R2D2

http://aksw.org/Projects/R2D2 an entity of type: AlumniProject

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.
xsd:string

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

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:

and is translated into the RDF result triple:

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.

sysont:Markdown
6.985563ms