Mapping Relational Databases to Linked Data

35
Mapping Relational Databases to Linked Data Barry Norton (presenting) Juan Sequeda

description

This presentation provides an introduction to mapping relational databases to Linked Data

Transcript of Mapping Relational Databases to Linked Data

Page 1: Mapping Relational Databases to Linked Data

Mapping Relational Databases to Linked

DataBarry Norton (presenting)

Juan Sequeda

Page 2: Mapping Relational Databases to Linked Data

2

W3C RDB2RDF Standards

• Standards to map relational data to RDF

• A Direct Mapping of Relational Data to RDF– Default automatic mapping of relational data to

RDF

• R2RML: RDB to RDF Mapping Language– Customizable language to map relational data to

RDF

RDB2RDF

Page 3: Mapping Relational Databases to Linked Data

RDBDirect Mapping

RDF

automatic

Direct Mapping

RDB2RDF 3

Page 4: Mapping Relational Databases to Linked Data

PersonID

(pk)NAME AGE

1 Alice 25

2 Bob NULL

4RDB2RDF

Direct Mapping on Table

Page 5: Mapping Relational Databases to Linked Data

ID (pk)

NAME AGE

1 Alice 25

2 Bob NULL

Person

5RDB2RDF

Direct Mapping on Table

Page 6: Mapping Relational Databases to Linked Data

ID (pk)

NAME AGE

1 Alice 25

2 Bob NULL

Person

<http://www.ex.com/Person/ID=1><http://www.ex.com/Person#NAME>

"Alice" .

6RDB2RDF

Direct Mapping on Table

Page 7: Mapping Relational Databases to Linked Data

ID (pk)

NAME

AGECID(fk)

1 Alice 25 100

2 BobNULL

200

7RDB2RDF

PersonCID (pk)

TITLE

100Austin

200Madri

d

CityDM on Table Join

Page 8: Mapping Relational Databases to Linked Data

8RDB2RDF

ID (pk)

NAME

AGECID(fk)

1 Alice 25 100

2 BobNULL

200

PersonCID (pk)

TITLE

100Austin

200Madri

d

City

<http://www.ex.com/Person/ID=1><http://www.ex.com/Person#CID>

"100" .

DM on Table Join

Page 9: Mapping Relational Databases to Linked Data

ID (pk)

NAME

AGECID(fk)

1 Alice 25 100

2 BobNULL

200

PersonCID (pk)

TITLE

100Austin

200Madri

d

City

<http://www.ex.com/Person/ID=1><http://www.ex.com/Person#ref-CID>

<http://www.ex.com/City/CID=100>. 9RDB2RDF

<http://www.ex.com/Person/ID=1><http://www.ex.com/Person#CID>

"100" .

DM on Table Join

Page 10: Mapping Relational Databases to Linked Data

10

DM Summary• Default and Automatic Mapping• URIs are automatically generated– <table>– <table#attribute>– <table#ref-attribute>– <Table#pkAttr=pkValue>

• RDF represents the same relational schema– Table Class– Attribute Property

RDB2RDF

Page 11: Mapping Relational Databases to Linked Data

RDB

RDF

R2RMLmanual

R2RML

11RDB2RDF

Page 12: Mapping Relational Databases to Linked Data

@prefix rr: <http://www.w3.org/ns/r2rml#> .@prefix foaf: <http://xmlns.com/foaf/0.1/> .@prefix ex: <http://example.com/> .@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .@base <http://example.com/base/> .

<TriplesMap1> a rr:TriplesMap; rr:logicalTable [ rr:tableName "Person" ];

rr:subjectMap [ rr:template "http://ex/person{ID}"; rr:class foaf:Person ];

rr:predicateObjectMap [ rr:predicate foaf:name ; rr:objectMap [ rr:column "NAME" ] ] .

12RDB2RDF

R2RML Mapping

Page 13: Mapping Relational Databases to Linked Data

<http://www.ex.com/Person/ID=1>

<http://www.ex.com/Person#NAME>

<http://www.ex.com/data/person1>

<http://xmlns.com/foaf/0.1/name>

‘Cool’ URIs

13RDB2RDF

Page 14: Mapping Relational Databases to Linked Data

@prefix rr: <http://www.w3.org/ns/r2rml#> .@prefix foaf: <http://xmlns.com/foaf/0.1/> .@prefix ex: <http://example.com/> .@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .@base <http://example.com/base/> .

<TriplesMap1> a rr:TriplesMap; rr:logicalTable [ rr:tableName "Person" ];

rr:subjectMap [ rr:template "http://ex/person{ID}"; rr:class foaf:Person ];

rr:predicateObjectMap [ rr:predicate foaf:name ; rr:objectMap [ rr:column "NAME" ] ] .

SubjectURI

14RDB2RDF

URI Templates

Page 15: Mapping Relational Databases to Linked Data

@prefix rr: <http://www.w3.org/ns/r2rml#> .@prefix foaf: <http://xmlns.com/foaf/0.1/> .@prefix ex: <http://example.com/> .@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .@base <http://example.com/base/> .

<TriplesMap1> a rr:TriplesMap; rr:logicalTable [ rr:tableName "Person" ];

rr:subjectMap [ rr:template "http://ex/person{ID}"; rr:class foaf:Person ];

rr:predicateObjectMap [ rr:predicate foaf:name ; rr:objectMap [ rr:column "NAME" ] ] .

PredicateURI

15RDB2RDF

Predicates

Page 16: Mapping Relational Databases to Linked Data

@prefix rr: <http://www.w3.org/ns/r2rml#> .@prefix foaf: <http://xmlns.com/foaf/0.1/> .@prefix ex: <http://example.com/> .@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .@base <http://example.com/base/> .

<TriplesMap1> a rr:TriplesMap; rr:logicalTable [ rr:tableName "Person" ];

rr:subjectMap [ rr:template "http://ex/Person{ID}"; rr:class foaf:Person ];

rr:predicateObjectMap [ rr:predicate foaf:name ; rr:objectMap [ rr:column "NAME" ] ] .

Object Value

16RDB2RDF

Object Maps

Page 17: Mapping Relational Databases to Linked Data

@prefix rr: <http://www.w3.org/ns/r2rml#> .@prefix foaf: <http://xmlns.com/foaf/0.1/> .@prefix ex: <http://example.com/> .@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .@base <http://example.com/base/> .

<TriplesMap1> a rr:TriplesMap; rr:logicalTable [ rr:tableName "Person" ];

rr:subjectMap [ rr:template "http://ex/Person{ID}"; rr:class foaf:Person];

rr:predicateObjectMap [ rr:predicate foaf:name ; rr:objectMap [ rr:column "NAME" ] ] . <subject uri> rdf:type foaf:Person

17RDB2RDF

Classes

Page 18: Mapping Relational Databases to Linked Data

<TriplesMap1> a rr:TriplesMap; rr:logicalTable [ rr:tableName"Person" ];

rr:subjectMap [ rr:template "http://ex/Person{ID}"; rr:class foaf:Person ];

rr:predicateObjectMap [ rr:predicate foaf:based_near ; rr:objectMap [

rr:parentTripleMap <TripleMap2>;rr:joinCondition [

rr:child "CID";rr:parent "CID"

]]

] .

<TriplesMap2> a rr:TriplesMap; rr:logicalTable [ rr:tableName "City" ];

rr:subjectMap [ rr:template "http://ex/City{CID}"; rr:class ex:City ];

rr:predicateObjectMap [ rr:predicate dc:title ; rr:objectMap [ rr:column "TITLE" ] ] .

18RDB2RDF

R2RML on Joins

Page 19: Mapping Relational Databases to Linked Data

SELECT gender, firstname, lastname FROM Person WHERE gender = "F"

ex:Person1 rdf:type ex:Woman .

ex:Person1 foaf:name "Alice Smith" .

Customized Mapping

19RDB2RDF

Page 20: Mapping Relational Databases to Linked Data

@prefix rr: <http://www.w3.org/ns/r2rml#> .@prefix foaf: <http://xmlns.com/foaf/0.1/> .@prefix ex: <http://example.com/> .@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .@base <http://example.com/base/> .

<TriplesMap1> a rr:TriplesMap; rr:logicalTable [ rr:sqlQuery

"""SELECT concat(firstname, " ", lastname) AS name

FROM Person WHERE gender = 'F' """];

rr:subjectMap [ rr:template "http://ex/Person{ID}"; rr:class ex:Woman];

rr:predicateObjectMap [ rr:predicate foaf:name ; rr:objectMap [ rr:column "name" ] ] .

20RDB2RDF

SQL Queries

Page 21: Mapping Relational Databases to Linked Data

21

R2RML• Manual and Customizable• Learning Curve• View relational data as RDF expressed in the

structure and target vocabulary of the mapping author’s choice

RDB2RDF

Page 22: Mapping Relational Databases to Linked Data

RDB

RDF

Dump

SPARQL

Extract – Transform – Load (ETL)

22RDB2RDF

Page 23: Mapping Relational Databases to Linked Data

RDB

Mapping

SPARQL

Wrapper System

RDF

SQL

SQLResults

SPARQLResults 23RDB2RDF

Page 24: Mapping Relational Databases to Linked Data

24

EUCLID Scenario

Visualization Module

Metadata

Streaming providers

Physical Wrapper

Downloads

Dat

a ac

quis

ition

R2R Transf.LD Wrapper

Musical Content

Appl

icati

on

Analysis & Mining Module

LD D

atas

etAc

cess

LD Wrapper

RDF/ XML

Integrated Dataset

Interlinking CleansingVocabulary Mapping

SPARQL Endpoint

Publishing

RDFa

Other content

Page 25: Mapping Relational Databases to Linked Data

25

W3C RDB2RDF• Task: Integrate data from

relational DBMS with Linked Data

• Approach: map from relational schema to semantic vocabulary with R2RML

• Publishing: two alternatives –– Translate SPARQL into SQL on

the fly– Batch transform data into RDF,

index and provide SPARQL access in a triplestore

LD D

atas

etAc

cess

Integrated Data in

Triplestore

Interlinking CleansingVocabulary Mapping

SPARQL Endpoint

Publishing

Dat

a ac

quis

ition

R2RMLEngine

RelationalDBMS

RDB2RDF

Page 26: Mapping Relational Databases to Linked Data

26

MusicBrainz Next Gen Schema

• artistAs pre-NGS, but

further attributes

• artist_creditAllows joint credit

• release_groupCf. ‘album’

versus:

• release• medium

• track• tracklist

• work• recording

https://wiki.musicbrainz.org/Next_Generation_Schema

RDB2RDF

Page 27: Mapping Relational Databases to Linked Data

27

Music Ontology• MusicArtist– ArtistEvent, member_of

• SignalGroup ‘Album’ as per Release_Group

• Release– ReleaseEvent

• Record• Track• Work• Compositionhttp://musicontology.com/

RDB2RDF

Page 28: Mapping Relational Databases to Linked Data

28

Scale• MusicBrainz RDF derived via R2RML:

lb:artist_member a rr:TriplesMap ; rr:logicalTable [rr:sqlQuery """SELECT a1.gid, a2.gid AS band FROM artist a1 INNER JOIN l_artist_artist ON a1.id = l_artist_artist.entity0 INNER JOIN link ON l_artist_artist.link = link.id INNER JOIN link_type ON link_type = link_type.id INNER JOIN artist a2 on l_artist_artist.entity1 = a2.id WHERE link_type.gid='5be4c609-9afa-4ea0-910b-12ffb71e3821'"""] ; rr:subjectMap [rr:template "http://musicbrainz.org/artist/{gid}#_"] ; rr:predicateObjectMap [rr:predicate mo:member_of ; rr:objectMap [rr:template "http://musicbrainz.org/artist/{band}#_" ; rr:termType rr:IRI]] .

300M Triples

Page 29: Mapping Relational Databases to Linked Data

29

R2RML Class Mapping• Mapping tables to classes is ‘easy’:

lb:Artist a rr:TriplesMap ; rr:logicalTable [rr:tableName "artist"] ; rr:subjectMap [rr:class mo:MusicArtist ; rr:template

"http://musicbrainz.org/artist/{gid}#_"] ; rr:predicateObjectMap [rr:predicate mo:musicbrainz_guid ; rr:objectMap [rr:column "gid" ; rr:datatype xsd:string]] .

RDB2RDF

Page 30: Mapping Relational Databases to Linked Data

RDB2RDF 30

R2RML Property Mapping• Mapping columns to properties can be easy:

lb:artist_name a rr:TriplesMap ; rr:logicalTable [rr:sqlQuery """SELECT artist.gid, artist_name.name FROM artist INNER JOIN artist_name ON artist.name =

artist_name.id"""] ; rr:subjectMap [rr:template

"http://musicbrainz.org/artist/{gid}#_"] ; rr:predicateObjectMap [rr:predicate foaf:name ; rr:objectMap [rr:column "name"]] .

Page 31: Mapping Relational Databases to Linked Data

31

NGS Advanced Relations

• Major entities (Artist, Release Group, Track, etc.) plus URL are paired(l_artist_artist)

• Each pairingof instancesrefers to a Link

• Links have types (cf. RDF properties)and attributes

http://wiki.musicbrainz.org/Advanced_Relationship

RDB2RDF

Page 32: Mapping Relational Databases to Linked Data

32

Advanced Relations Mapping

• Mapping advanced relationships (SQL joins):lb:artist_member a rr:TriplesMap ; rr:logicalTable [rr:sqlQuery """SELECT a1.gid, a2.gid AS band FROM artist a1 INNER JOIN l_artist_artist ON a1.id = l_artist_artist.entity0 INNER JOIN link ON l_artist_artist.link = link.id INNER JOIN link_type ON link_type = link_type.id INNER JOIN artist a2 on l_artist_artist.entity1 = a2.id WHERE link_type.gid='5be4c609-9afa-4ea0-910b-

12ffb71e3821'"""] ; rr:subjectMap [rr:template

"http://musicbrainz.org/artist/{gid}#_"] ; rr:predicateObjectMap [rr:predicate mo:member_of ; rr:objectMap [rr:template

"http://musicbrainz.org/artist/{band}#_" ; rr:termType rr:IRI]] .

RDB2RDF

Page 33: Mapping Relational Databases to Linked Data

33

Advanced Relations Mapping

• Mapping advanced relationships (SQL joins):lb:artist_dbpedia a rr:TriplesMap ; rr:logicalTable [rr:sqlQuery """SELECT artist.gid, REPLACE(REPLACE(url, 'wikipedia.org/wiki', 'dbpedia.org/resource'), 'http://en.', 'http://') AS url FROM artist INNER JOIN l_artist_url ON artist.id = l_artist_url.entity0 INNER JOIN link ON l_artist_url.link = link.id INNER JOIN link_type ON link_type = link_type.id INNER JOIN url on l_artist_url.entity1 = url.id WHERE link_type.gid='29651736-fa6d-48e4-aadc-a557c6add1cb' AND url SIMILAR TO 'http://(de|el|en|es|ko|pl|pt).wikipedia.org/wiki/%'"""] ; rr:subjectMap lb:sm_artist ; rr:predicateObjectMap [rr:predicate owl:sameAs ; rr:objectMap [rr:column "url"; rr:termType rr:IRI]] .

RDB2RDF

Page 34: Mapping Relational Databases to Linked Data

34

SPARQL Example• SPARQL versus SQLASK {dbp:Paul_McCartney mo:member dbp:The_Beatles}

SELECT …

INNER JOININNER JOININNER JOININNER JOININNER JOININNER JOININNER JOININNER JOININNER JOININNER JOININNER JOININNER JOINWHERE AND … AND … AND … AND …

RDB2RDF

Page 35: Mapping Relational Databases to Linked Data

35

For exercises, quiz and further material visit our website:

@euclid_project EUCLID project EUCLIDproject

http://www.euclid-project.eu

Other channels:

eBook Course