Skip to content
Guohui Xiao edited this page Sep 18, 2013 · 2 revisions
Still under heavy construction. The current content is only a first rough descripton of the final product

Table of Contents

Description

This feature of the OBDA plugin allows us to import D2R mappings and translate them into equivalent Quest mappings as well as to export a set of Quest mappings and translate them in to equivalent D2R mappings.

D2R

D2R is a declarative language to describe mappings between relational database schemas and OWL ontologies and can be used to export data from a relational database into RDF. Its main features are:

  • Flexible mapping of complex relational structures without having to change existing database schema.
  • Handling of highly normalized table structures, where instance data is spread over several tables.
  • References to resources and blank nodes created on the fly.
  • Support for multivalued class properties and RDF containers like rdf:Bag, rdf:Alt or rdf:Seq.
  • Support for XML datatypes and xml:lang attributes.
  • Property value transformations using patterns and value substitution tables.
Further informations as well as the language specification and document type specification of D2R can be found here

Importing D2R mappings

The import mechansim allows you to translate a set of D2R mappings into Quest mappings. A detailed description of the mapping language used by Quest can be found here. The import will consist of three major steps:

  • import and translate the data source specifications
  • import and translate namspace declarations
  • import and translate the mappings.
The import will add a new data source to the data source manager using the information given in the mapping. Furthermore the prefix declarations will be inserted into the prefix manager of Protégé, so that the abbreviations are translated correctly. Finally, we will produce for each d2r:ClassMap element a new Quest mapping.

Example

Suppose we have the following D2R mapping

<?xml version="1.0"?>
<d2r:Map xmlns:d2r="http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RMap/0.1#">
  <d2r:DBConnection d2r:jdbcDSN="bookDB" d2r:jdbcDriver="org.postgresql.Driver" d2r:username="postgres" d2r:password="pwd"/>
  <d2r:Namespace d2r:prefix="ex" d2r:namespace="http://example.org#"/>
  <d2r:ClassMap d2r:type="ex:Book" d2r:sql="SELECT isbn, title FROM books;" d2r:groupBy="isbn"
    d2r:uriPattern="ex:book@@isbn@@">
    <d2r:DatatypePropertyBridge d2r:property="ex:title" d2r:column="title" xml:lang="en"/>
  </d2r:classmap>
</d2r:map>

This mapping will add a new data source to the OBDA plugin with the specified name, driver, username and password. It also will add the two namespace declarations of ex and rdf to the Protégé prefix manager. Finally, the import mechanism will create a mapping for the given d2r:ClassMap element. In the Body of the Quest mapping we put the SQL query and in the head of the mapping we insert a conjuctive query with two atoms, a unary atom for the class ex:book and a binary atom data property ex:title. The resulting mapping will be:

m1: SELECT isbn, title FROM books → q($isbn, $title) :- ex:Book(isbn($isbn)), ex:title(isbn($isbn),$title)

Exporting D2R mappings

The export mechansim allows you to translate a set of Quest mappings into equivalent D2R mappings. The export consist of three major steps:

  • translate and export the data source specifications
  • translate and export namspace declarations
  • translate and export the mappings.
The export will encode the currently selected data source and add it to the d2r:Map element of the D2R mapping. Similarly all needed prefix declations will be added to the mapping and finally all d2r:ClassMap elements are inserted.

Example

Suppose the follwing mapping

m1: SELECT id, name FROM employee  → q($id, $name) :- ex:Person(id($uri)), ex:has-name(id($uri),$name)

associated to the a data source

name = exDB
username = postgres
password = pwd
driver = org.postgresql.Driver

In the first step we add the data source element to the d2r:Map element (our root element). So as a partial result we get

<?xml version="1.0"?>
<d2r:Map xmlns:d2r="http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RMap/0.1#">
  <d2r:DBConnection d2r:jdbcDSN="exDB" d2r:jdbcDriver="org.postgresql.Driver" d2r:username="postgres" d2r:password="pwd"/>
</d2r:map>
In the next step we add the namspace elements to the mapping. In this case we add a namspace definition with prefix ex and namespaceuri http://example.org#
<?xml version="1.0"?>
<d2r:Map xmlns:d2r="http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RMap/0.1#">
  <d2r:DBConnection d2r:jdbcDSN="exDB" d2r:jdbcDriver="org.postgresql.Driver" d2r:username="postgres" d2r:password="pwd"/>
  <d2r:Namespace d2r:prefix="ex" d2r:namespace="http://example.org#"/>
</d2r:map>

and finally we add the d2r:ClassMap for our Quest mapping. As d2r:type we put ex:Person, as d2r:sql we take the body of the mapping and as d2r:groupBy we take the variable used in the Person atom. In order to take into account the has-name data property we add a d2r:DatatypePropertyBridge to the d2r:ClassMap element and set the atrributes d2r:property="ex:has-name" and d2r:column="name". It is also possible to specify the type and the language of the data property, but since in this example we don't know those values we just skip them. So the final D2R mappings looks as follow:

<?xml version="1.0"?>
<d2r:Map xmlns:d2r="http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RMap/0.1#">
  <d2r:DBConnection d2r:jdbcDSN="exDB" d2r:jdbcDriver="org.postgresql.Driver" d2r:username="postgres" d2r:password="pwd"/>
  <d2r:Namespace d2r:prefix="ex" d2r:namespace="http://example.org#"/>
  <d2r:ClassMap d2r:type="ex:Person" d2r:sql="SELECT id, name FROM employee" d2r:groupBy="id">
    <d2r:DatatypePropertyBridge d2r:property="ex:title" d2r:column="title" xml:lang="en"/>
  </d2r:classmap>
</d2r:map>
Clone this wiki locally