RDB2RDF Working Group Cunxin Jia
Why Mapping RDBs to RDF?
W3C RDB2RDF Working Group The mission of the RDB2RDF Working Group, part of the Semantic Web Activity, is to standardize languages for mapping relational data and relational database schemas into RDF and OWL.Semantic Web Activity Direct Mapping (DM) RDB2RDF Mapping Language (R2RML).
Milestone SpecificationFPWDLCCRPR Rec, WG Note, Wiki page Working Draft Candidate Recommendation Proposed Recommendation R2RML2010/92011/92011/ /3 2012/8/ /6 (Rec) Direct Mapping 2010/92011/92011/ /3 2012/8/ /6 (Rec) R2RML Test Cases 2010/92012/1 2012/3 (Wiki pages) Direct Mapping Test Cases 2010/92012/1 2012/3 (Wiki pages)
R2RML: RDB to RDF Mapping Language A language for expressing customized mappings from relational databases to RDF datasets. Expressed as RDF graphs and written down in Turtle syntax. Input: RDB Output: RDF dataset
Example Input Database EMPNO INTEGER PRIMARY KEY ENAME VARCHAR(100) JOB VARCHAR(20) DEPTNO INTEGER REFERENCES DEPT (DEPTNO) 7369SMITHCLERK10 DEPTNO INTEGER PRIMARY KEY DNAME VARCHAR(30) LOC VARCHAR(100) 10APPSERVERNEW YORK EMP DEPT
Desired RDF Output rdf:type ex:Employee. ex:name "SMITH". ex:department. rdf:type ex:Department. ex:name "APPSERVER". ex:location "NEW YORK". ex:staff 1. < rdf:type ex:Employee. < ex:name "SMITH". < ex:department < < rdf:type ex:Department. < ex:name "APPSERVER". < ex:location "NEW YORK". < ex:staff 1.
Mapping a Simple ex:. rr:logicalTable [ rr:tableName "EMP" ]; rr:subjectMap [ rr:template " rr:class ex:Employee; ]; rr:predicateObjectMap [ rr:predicate ex:name; rr:objectMap [ rr:column "ENAME" ]; ex:. rr:logicalTable [ rr:tableName "EMP" ]; rr:subjectMap [ rr:template " rr:class ex:Employee; ]; rr:predicateObjectMap [ rr:predicate ex:name; rr:objectMap [ rr:column "ENAME" ]; ]. rdf:type ex:Employee. ex:name "SMITH".
Computing a Property with an R2RML View rr:sqlQuery """ SELECT DEPTNO, DNAME, LOC, (SELECT COUNT(*) FROM EMP WHERE EMP.DEPTNO=DEPT.DEPTNO) AS STAFF FROM DEPT; """. rr:sqlQuery """ SELECT DEPTNO, DNAME, LOC, (SELECT COUNT(*) FROM EMP WHERE EMP.DEPTNO=DEPT.DEPTNO) AS STAFF FROM DEPT; """. rr:logicalTable ; rr:subjectMap [ rr:template " rr:class ex:Department; ]; rr:predicateObjectMap [ rr:predicate ex:name; rr:objectMap [ rr:column "DNAME" ]; ]; rr:predicateObjectMap [ rr:predicate ex:location; rr:objectMap [ rr:column "LOC" ]; ]; rr:predicateObjectMap [ rr:predicate ex:staff; rr:objectMap [ rr:column "STAFF" ]; ]. rr:logicalTable ; rr:subjectMap [ rr:template " rr:class ex:Department; ]; rr:predicateObjectMap [ rr:predicate ex:name; rr:objectMap [ rr:column "DNAME" ]; ]; rr:predicateObjectMap [ rr:predicate ex:location; rr:objectMap [ rr:column "LOC" ]; ]; rr:predicateObjectMap [ rr:predicate ex:staff; rr:objectMap [ rr:column "STAFF" ]; ]. rdf:type ex:Department. ex:name "APPSERVER". ex:location "NEW YORK". ex:staff 1.
Linking Two Tables rr:predicateObjectMap [ rr:predicate ex:department; rr:objectMap [ rr:parentTriplesMap ; rr:joinCondition [ rr:child "DEPTNO"; rr:parent "DEPTNO"; ]; ]. rr:predicateObjectMap [ rr:predicate ex:department; rr:objectMap [ rr:parentTriplesMap ; rr:joinCondition [ rr:child "DEPTNO"; rr:parent "DEPTNO"; ]; ]. ex:department.
R2RML vocabulary rr :. rr:TriplesMap is the class of triples maps.triples maps rr:LogicalTable is the class of logical tables. It has two subclasses:logical tables rr:R2RMLView is the class of R2RML views.R2RML views rr:BaseTableOrView is the class of SQL base tables or views.SQL base tables or views rr:TermMap is the class of term maps. It has four subclasses:term maps rr:SubjectMap is the class of subject maps.subject maps rr:PredicateMap is the class of predicate maps.predicate maps rr:ObjectMap is the class of object maps.object maps rr:GraphMap is the class of graph maps.graph maps rr:PredicateObjectMap is the class of predicate-object maps.predicate-object maps rr:RefObjectMap is the class of referencing object maps.referencing object maps rr:Join is the class of join conditions.join conditions
Triples Map [] rr:logicalTable [ rr:tableName "DEPT" ]; rr:subjectMap [ rr:template " ]; rr:predicateObjectMap [ rr:predicate ex:name; rr:objectMap [ rr:column "DNAME" ]; ]; rr:predicateObjectMap [ rr:predicate ex:location; rr:objectMap [ rr:column "LOC" ]; ]. [] rr:logicalTable [ rr:tableName "DEPT" ]; rr:subjectMap [ rr:template " ]; rr:predicateObjectMap [ rr:predicate ex:name; rr:objectMap [ rr:column "DNAME" ]; ]; rr:predicateObjectMap [ rr:predicate ex:location; rr:objectMap [ rr:column "LOC" ]; ]. Exactly one rr:logicalTable Exactly one rr:subjectMap Zero or more rr:predicateObjectMap
Logical Table rr:sqlQuery """ SELECT DEPTNO, DNAME, LOC, (SELECT COUNT(*) FROM EMP WHERE EMP.DEPTNO=DEPT.DEPTNO) AS STAFF FROM DEPT; """. rr:sqlQuery """ SELECT DEPTNO, DNAME, LOC, (SELECT COUNT(*) FROM EMP WHERE EMP.DEPTNO=DEPT.DEPTNO) AS STAFF FROM DEPT; """. A SQL base table or view An R2RML view
Subject Map [] rr:template " rr:class ex:Employee. [] rr:template " rr:class ex:Employee. A template to generate IRI for each row Class IRIs
PredicateObject Map One or more predicate maps. One or more object maps or referencing object maps. rr:predicateObjectMap [ rr:predicate ex:location; rr:objectMap [ rr:column "LOC" ]; ]. rr:predicateObjectMap [ rr:predicate ex:location; rr:objectMap [ rr:column "LOC" ]; ]. rr:predicateObjectMap [ rr:predicate ex:department; rr:objectMap [ rr:parentTriplesMap ; rr:joinCondition [ rr:child "DEPTNO"; rr:parent "DEPTNO"; ]; ]. rr:predicateObjectMap [ rr:predicate ex:department; rr:objectMap [ rr:parentTriplesMap ; rr:joinCondition [ rr:child "DEPTNO"; rr:parent "DEPTNO"; ]; ].
Natural RDF literal SQL datatypeRDF datatype Lexical transformation (informative) BINARY, BINARY VARYING, BINARY LARGE OBJECT xsd:hexBinary xsd:hexBinary lexical mapping NUMERIC, DECIMALxsd:decimalnone required SMALLINT, INTEGER, BIGINT xsd:integernone required FLOAT, REAL, DOUB LE PRECISION xsd:doublenone required BOOLEANxsd:boolean ensure lowercase (true, false) DATExsd:datenone required TIMExsd:timenone required TIMESTAMPxsd:dateTime replace space character with “T” INTERVALundefined
An overview of R2RML
DM:A Direct Mapping of Relational Data to RDF The direct mapping defines a simple transformation. R2RML defines a relaxed variant of the Direct Mapping intended as a default mapping for further customization. Input: RDB Output: RDF graph
Example Input Database ID INTEGER PRIMARY KEY fname VARCHAR(10) addr INTEGER REFERENCES Address(ID) 7Bob18 8SueNULL ID INTEGER PRIMARY KEY city VARCHAR(10) state VARCHAR(2) 18CambridgeMA People Address
Desired xsd:. rdf:type. 7. "Bob" rdf:type. 8. "Sue". rdf:type xsd:. rdf:type. 7. "Bob" rdf:type. 8. "Sue". rdf:type. 18. "Cambridge". "MA".
An overview of DM
R2RML vs. DM R2RML is customized. DM is default and automatic.
The End