Ontology Engineering Lab #12

Download Report

Transcript Ontology Engineering Lab #12

Lab #9 - November 3, 2014
Linking Relational Databases to
Relational databases are still a common means of
storing information
An enterprise may have many databases that
contain information describing different (but
possibly overlapping) portions of their domain
How to achieve a unified view of this information
when it is not always possible or desirable to collect
it into a single store?
Database to Ontology Mapping
Such languages provide the ability to
 View
existing relational data in the RDF data model,
 Express in the information in a structure and target
vocabulary of the mapping author's choice.
- http://www.w3.org/TR/r2rml/
 D2RQ - http://d2rq.org/
 R2O - http://neon-toolkit.org/wiki/ODEMapster
 EDOAL - http://alignapi.gforge.inria.fr/edoal.html
D2RQ Mapping Language
The homepage can be found at: http://d2rq.org/ and
the language specification is available at:
A D2RQ mapping is an RDF document written in Turtle
syntax and expressed using terms in the D2RQ
Basic structure of a mapping:
Database columns are mapped to ontology classes using
instances of d2rq:ClassMap
 Relations between columns are mapped to ontology
properties using instances of d2rq:PropertyBridge
D2RQ Mapping File As Class Instances
map:database rdf:type d2rq:Database ;
jdbc:autoReconnect "true" ;
jdbc:zeroDateTimeBehavior "convertToNull" ;
d2rq:jdbcDSN "jdbc:mysql://localhost/vast2010" ;
d2rq:jdbcDriver "com.mysql.jdbc.Driver" ;
d2rq:username "root" ;
d2rq:password “abc321" .
map:Person rdf:type d2rq:ClassMap ;
rdfs:label "Person"^^xsd:string ;
d2rq:class agent:Person ;
d2rq:classDefinitionComment "Hospital Records Person"^^xsd:string ;
d2rq:dataStorage map:database ;
"hospitalrecords_Person/@@[email protected]@"^^xsd:string .
D2RQ Mapping File as Class Instances
map:PersonAge rdf:type d2rq:ClassMap ;
rdfs:label "Person age"^^xsd:string ;
d2rq:class quality:ChronologicalAge ;
d2rq:classDefinitionLabel "Hospital Records Person Age"^^xsd:string ;
d2rq:dataStorage map:database ;
"hospitalrecords_PersonAge/@@[email protected]@"^^xsd:string .
map:person_Age rdf:type d2rq:PropertyBridge ;
rdfs:label "person Age"^^xsd:string ;
d2rq:belongsToClassMap map:Person ;
d2rq:property ero:has_quality ;
d2rq:propertyDefinitionLabel "Person Age"^^xsd:string ;
d2rq:refersToClassMap map:PersonAge .
D2RQ Mapping File as Class Instances
map:person_Age_Value rdf:type d2rq:PropertyBridge ;
rdfs:label "person Age Value"^^xsd:string ;
d2rq:belongsToClassMap map:PersonAge ;
dr2q:column “hospitalrecords.age”^^xsd:integer;
d2rq:property info:has_integer_value;
d2rq:propertyDefinitionLabel "Person Age"^^xsd:string .
Mappings Enable SPARQL Queries of
Relational Data
SELECT ?person ?agevalue
?person rdf:type agent:Person .
?age rdf:type quality:ChronologicalAge .
?person ero:has_quality ?age
?age info:has_integer_value ?agevalue
Installing and Running D2R SPARQL
Download and unzip the d2rq-0.8.1.zip file (latest version as
of 11/03/14)
Create a mapping file in .ttl format and place it into the d2rserver working directory
Open a command prompt and navigate to the working
directory of the d2r-server.
 Ex: cd “C:\Program Files\d2r-server-v8\d2rq-0.8.1“
Run the d2r-server using this command: d2r-server file_name.ttl
(where file_name.ttl is the name of a mapping file you’ve created)
If any, examine the error messages, they're trying to tell you
something, most often that there's some syntax errors in your
Installing and Running D2R SPARQL
If there are no errors, open your browser and enter:
http://localhost:2020/snorql/ in the address bar
If a SPARQL query window doesn't open you've done
something wrong, for example make certain that the database
is up and running
Use Ctrl-c to stop the d2r server and get back to the command
Other D2RQ Tools
The generate-mapping tool creates a mapping file that
maps each table to a new RDFS class that is based on the
table's name, and maps each column to a property based
on the column's name. This mapping file can be used as-is or
can be customized.
At the command prompt enter:
generate-mapping –o customer_record.ttl –u root –p abc123
-o is the name of the output mapping file
-u is the database user name
-p is user’s password
jdbc:… is the connection string including the name of the mysql database
(i.e. customer_record)
Other D2RQ Tools
The dump-rdf tool outputs the contents of the whole
database into a single RDF file. If a mapping file is
specified, then the tool will use it to translate the database
contents to RDF. If no mapping file is specified, then the tool
will use the default mapping of generate-mapping for the
At the command prompt enter:
dump-rdf –o dump_customer_record.n3 mapping_file.ttl
- o is the name of the output file
“mapping_file.ttl” is the name of the mapping file to be used
in generating the output.
Other D2RQ Tools
The d2r-query tool allows executing SPARQL
queries against a relational database from the
command line. If a mapping file is specified, then
the tool will query the virtual RDF graph defined by
the mapping. If no mapping file is specified, then
the tool will use the default mapping of generatemapping for the translation.