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 2
3. Direct Mapping
automatic
Direct
RDB Mapping
RDF
RDB2RDF 3
4. Direct Mapping on Table
Person
ID (pk) NAME AGE
1 Alice 25
2 Bob NULL
RDB2RDF 4
5. Direct Mapping on Table
Person
ID (pk) NAME AGE
1 Alice 25
2 Bob NULL
RDB2RDF 5
6. Direct Mapping on Table
Person
ID (pk) NAME AGE
1 Alice 25
2 Bob NULL
<http://www.ex.com/Person/ID=1>
<http://www.ex.com/Person#NAME>
"Alice" .
RDB2RDF 6
7. DM on Table Join
Person City
ID CID CID
NAME AGE TITLE
(pk) (fk) (pk)
1 Alice 25 100 100 Austin
2 Bob NULL 200 200 Madrid
RDB2RDF 7
8. DM on Table Join
Person City
ID CID CID
NAME AGE TITLE
(pk) (fk) (pk)
1 Alice 25 100 100 Austin
2 Bob NULL 200 200 Madrid
<http://www.ex.com/Person/ID=1>
<http://www.ex.com/Person#CID>
"100" .
RDB2RDF 8
9. DM on Table Join
Person City
ID CID CID
NAME AGE TITLE
(pk) (fk) (pk)
1 Alice 25 100 100 Austin
2 Bob NULL 200 200 Madrid
<http://www.ex.com/Person/ID=1>
<http://www.ex.com/Person#CID>
"100" .
<http://www.ex.com/Person/ID=1>
<http://www.ex.com/Person#ref-CID>
<http://www.ex.com/City/CID=100>.
RDB2RDF 9
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 10
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 21
25. W3C RDB2RDF
• Task: Integrate data from
SPARQL relational DBMS with
Access
Endpoint Linked Data
Publishing
• Approach: map from
Integrated R2RML relational schema to
Data in Engine
LD Dataset
Triplestore semantic vocabulary with
R2RML
Vocabulary
Interlinking Cleansing • Publishing: two
Mapping
alternatives –
– Translate SPARQL into SQL
Data acquisition
on the fly
– Batch transform data into
Relational
DBMS
RDF, index and provide
SPARQL access in a
triplestore
RDB2RDF 25
26. MusicBrainz Next Gen Schema
• artist
As pre-NGS, but
further attributes
• artist_credit
Allows joint credit
• release_group
Cf. ‘album’
versus:
• release • track • work
• medium • tracklist • recording
https://wiki.musicbrainz.org/Next_Generation_Schema
RDB2RDF 26
27. Music Ontology
• MusicArtist
– ArtistEvent, member_of
• SignalGroup
‘Album’ as per Release_Group
• Release
– ReleaseEvent
• Record
• Track
• Work
• Composition
http://musicontology.com/
RDB2RDF 27
28. Scale
• MusicBrainz RDF derived via R2RML:
300M
Triples
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]] .
28
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 29
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"]] .
RDB2RDF 30
31. NGS Advanced Relations
• Major entities (Artist, Release Group, Track, etc.) plus
URL are paired
(l_artist_artist)
• Each pairing
of instances
refers to a Link
• Links have types
(cf. RDF properties)
and attributes
http://wiki.musicbrainz.org/Advanced_Relationship
RDB2RDF 31
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 32
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 33
34. SPARQL Example
• SPARQL versus SQL
ASK {dbp:Paul_McCartney mo:member dbp:The_Beatles}
SELECT …
INNER JOIN
INNER JOIN
INNER JOIN
INNER JOIN
INNER JOIN
INNER JOIN
INNER JOIN
INNER JOIN
INNER JOIN
INNER JOIN
INNER JOIN
INNER JOIN
WHERE AND … AND … AND … AND …
RDB2RDF 34
35. For exercises, quiz and further material visit our website:
http://www.euclid-project.eu
eBook Course
Other channels:
@euclid_project EUCLID project EUCLIDproject
35