Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Mapping Relational Databases to Linked Data

2,292 views

Published on

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

Published in: Technology
  • If you enjoyed this slideset, please do take a lot at the extended webinar version now available at:
    http://www.slideshare.net/EUCLIDproject/relational-database-to-rdf-rdb2rdf

    The webinar itself will shortly be available on Vimeo
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Mapping Relational Databases to Linked Data

  1. 1. Mapping Relational Databases to Linked Data Barry Norton (presenting) Juan Sequeda
  2. 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. 3. Direct Mapping automatic Direct RDB Mapping RDF RDB2RDF 3
  4. 4. Direct Mapping on Table Person ID (pk) NAME AGE 1 Alice 25 2 Bob NULL RDB2RDF 4
  5. 5. Direct Mapping on Table Person ID (pk) NAME AGE 1 Alice 25 2 Bob NULL RDB2RDF 5
  6. 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. 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. 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. 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. 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
  11. 11. R2RML RDB manual R2RML RDF RDB2RDF 11
  12. 12. R2RML Mapping@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" ] ] . RDB2RDF 12
  13. 13. ‘Cool’ URIs <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> RDB2RDF 13
  14. 14. URI Templates@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#> . Subject@base <http://example.com/base/> . URI<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" ] ] . RDB2RDF 14
  15. 15. Predicates@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 [ Predicate rr:predicate foaf:name ; URI rr:objectMap [ rr:column "NAME" ] ] . RDB2RDF 15
  16. 16. Object Maps@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 ; Object rr:objectMap [ rr:column "NAME" ] ] Value . RDB2RDF 16
  17. 17. Classes@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 RDB2RDF 17
  18. 18. R2RML on Joins<TriplesMap1> a rr:TriplesMap; rr:logicalTable [ rr:tableName"Person" ]; rr:subjectMap [ rr:template "http://ex/Person{ID}"; rr:class foaf:Person ]; rr:predicateObjectMap [ <TriplesMap2> rr:predicate foaf:based_near ; a rr:TriplesMap; rr:objectMap [ rr:logicalTable rr:parentTripleMap <TripleMap2>; rr:joinCondition [ [ rr:tableName "City" ]; rr:child "CID"; rr:parent "CID" rr:subjectMap ] [ rr:template ] "http://ex/City{CID}"; ] rr:class ex:City ]; . rr:predicateObjectMap [ rr:predicate dc:title ; rr:objectMap [ rr:column "TITLE" ] ]. RDB2RDF 18
  19. 19. Customized Mapping SELECT gender, firstname, lastname FROM Person WHERE gender = "F" ex:Person1 rdf:type ex:Woman . ex:Person1 foaf:name "Alice Smith" . RDB2RDF 19
  20. 20. SQL Queries@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" ] ] . RDB2RDF 20
  21. 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
  22. 22. Extract – Transform – Load(ETL) SPARQL RDB Dump RDF RDB2RDF 22
  23. 23. Wrapper System SQL SPARQL RDB Mapping SQL Results RDF SPARQL RDB2RDF Results 23
  24. 24. EUCLID ScenarioApplication Analysis & Visualization RDFa Module Mining ModuleAccess SPARQL Endpoint PublishingLD Dataset Vocabulary Integrated Interlinking Cleansing Mapping Dataset Physical Wrapper LD Wrapper R2R Transf. LD WrapperData acquisition RDF/ XML Streaming providers Downloads Musical Content Metadata Other content 24
  25. 25. W3C RDB2RDF • Task: Integrate data from SPARQL relational DBMS withAccess Endpoint Linked Data Publishing • Approach: map from Integrated R2RML relational schema to Data in EngineLD 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. 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 • recordinghttps://wiki.musicbrainz.org/Next_Generation_Schema RDB2RDF 26
  27. 27. Music Ontology• MusicArtist – ArtistEvent, member_of• SignalGroup ‘Album’ as per Release_Group• Release – ReleaseEvent• Record• Track• Work• Compositionhttp://musicontology.com/ RDB2RDF 27
  28. 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. 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. 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. 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 attributeshttp://wiki.musicbrainz.org/Advanced_Relationship RDB2RDF 31
  32. 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. 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. 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 34
  35. 35. For exercises, quiz and further material visit our website: http://www.euclid-project.eu eBook CourseOther channels: @euclid_project EUCLID project EUCLIDproject 35

×