Warning:
This wiki has been archived and is now read-only.
R2RML in Turtle
From RDB2RDF
This page gives an example for a proposed RDF serialization of R2RML. It uses the Turtle RDF syntax. This is a direct translation of the example presented for the XML-based proposal.
Raw files
Raw files of this Turtle example and the equivalent XML example are available here:
- http://github.com/cygri/r2rml/raw/master/examples/emp-dept.xml
- http://github.com/cygri/r2rml/raw/master/examples/emp-dept.ttl
Sample relational schema
DEPT table
deptno NUMBER UNIQUE dname VARCHAR2(30) loc VARCHAR2(100)
EMP table
empno NUMBER PRIMARY KEY ename VARCHAR2(100) job VARCHAR2(30) deptno NUMBER REFERENCES DEPT(deptno) etype VARCHAR2(30)
Sample mapping specification
This specification maps the above relational schema to RDF. This example includes:
- rdf:type columns
- destination graphs (either at class-level or at instance-level)
- inverse functions
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rr: <http://www.w3.org/ns/r2rml#> . @prefix emp: <http://example.com/emp#> . @prefix dept: <http://example.com/dept#> . @prefix xyz: <http://example.com/xyz#> . <#classMap1> a rr:ClassMap; rr:class xyz:dept; rr:graph xyz:DeptGraph; rr:sqlDefString """ Select 'xyz.com/dept/' || deptno' AS deptURI , deptno , dname , loc from dept"""; rr:instanceIdMap [ a rr:IRIMap; rr:column "deptURI" ]; rr:propertyMap [ rr:property dept:deptno; rr:column "deptno" ]; rr:propertyMap [ rr:property dept:name; rr:column "dname" ]; rr:propertyMap [ rr:property dept:location; rr:column "loc" ]; rr:uniqueKeyMap [ rr:key "c_unq_deptno"; rr:property dept:deptno ]; . <#classMap2> a rr:ClassMap; rr:class xyz:emp; rr:sqlDefString """ Select 'xyz.com/emp/' || empno AS empURI , empno , ename , 'xyz.com/emp/job/'|| job AS jobTypeURI , job , deptno , 'xyz.com/emp/etype/'|| etype AS empTypeURI , etype , 'xyz.com/graph/'|| job || '/' || etype AS graphURI from emp"""; rr:instanceIdMap [ a rr:IRIMap; rr:column "empURI" ]; rr:graphURIPropertyMap [ rr:property emp:destGraph; rr:column "graphURI" ]; rr:propertyMap [ rr:property rdf:type; rr:column "jobTypeURI" ]; rr:propertyMap [ rr:property rdf:type; rr:column "empTypeURI" ]; rr:propertyMap [ rr:property emp:empno; rr:column "empno" ]; rr:propertyMap [ rr:property emp:name; rr:column "ename" ]; rr:propertyMap [ rr:property emp:job; rr:column "job" ]; rr:propertyMap [ rr:property emp:deptNum; rr:column "deptno" ]; rr:propertyMap [ rr:property emp:etype; rr:column "etype" ]; rr:foreignKeyMap [ rr:key "c_ref_deptno"; rr:parentClass "xyz:dept"; rr:joinCondition "{child}.deptno = {parent}.deptno"; ]; .