Example of SQL-based RDB2RDF Mapping: Revision 2

From RDB2RDF
Jump to: navigation, search

A 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)

LIKES table -- attr-val table (sample row: "xyz.com/100" "likesPlaying" "Soccer")

 id       VARCHAR2(4000)
 likeType VARCHAR2(30)
 likedObj VARCHAR2(100)


A mapping specification (for mapping the above relational schema to RDF):

This example includes

 o bNode instance ID and IRI instance ID
 o inverse expression
 o rdf:type columns 
 o computed properties
 o destination graphs (either at class-level or at instance-level)
 o foreign key constraint

Note: Expansion for prefixes "dept:" and "emp:" have not been shown.

Mapping specification (expressed using an XML-based syntax)

<?xml version="1.0" ?> 
<rdb2rdf_sample xmlns:xyz="http://xyz.com" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
 <ClassMap ClassName="xyz:dept" GraphName="xyz:DeptGraph">
  <SQLdefString>
   Select 'dept' || deptno AS deptId
        , deptno
        , dname
        , loc 
     from dept
  </SQLdefString> 
  <InstanceIdMap DBColumnName="deptId" RDFTerm="bNode" 
                 InverseExpr="substr({alias}.deptId,length('dept')+1)" /> 
  <PropertyMap PropertyName="dept:deptno" DBColumnName="deptno" /> 
  <PropertyMap PropertyName="dept:Name" DBColumnName="dname" /> 
  <PropertyMap PropertyName="dept:location" DBColumnName="loc" /> 
  <PropertyMap PropertyName="dept:COMPANY" ConstantValue="XYZ Corporation" /> 
 </ClassMap>
 <ClassMap ClassName="xyz:emp">
  <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
  </SQLDefString> 
  <InstanceIdMap DBColumnName="empURI" RDFTerm="IRI"/> 
  <RDFTypeURIPropertyMap RDFTypeURIPropertyName="emp:jobtype" DBColumnName="jobTypeURI" /> 
  <RDFTypeURIPropertyMap RDFTypeURIPropertyName="emp:emptype" DBColumnName="empTypeURI" /> 
  <GraphURIPropertyMap GraphURIPropertyName="emp:destGraph" DBColumnName="graphURI" /> 
  <PropertyMap PropertyName="emp:empno" DBColumnName="empno" /> 
  <PropertyMap PropertyName="emp:Name" DBColumnName="ename" /> 
  <PropertyMap PropertyName="emp:job" DBColumnName="job" /> 
  <PropertyMap PropertyName="emp:deptNum" DBColumnName="deptno" /> 
  <PropertyMap PropertyName="emp:etype" DBColumnName="etype" /> 
  <ForeignKeyPropertyMap 
    ForeignKeyPropertyName="emp:c_ref_deptno" 
    ParentClassName="xyz:dept"
    JoinCondition="{child}.deptno = {parent}.deptno" 
  />
 </ClassMap>
 <ClassMap ClassName="xyz:likes" GraphName="xyz:LikesGraph">
  <SQLdefString>
   Select id
        , likeType
        , likedObj
     from likes
  </SQLdefString> 
  <InstanceIdMap DBColumnName="id" RDFTerm="IRI" /> 
  <ComputedPropertyMap ComputedPropertyName="likes:likeType" 
                       DBColumnName="likeType" />
  <PropertyMap PropertyName="likes:likeType"
               PropertyNameIsComputedPropertyMap="true" 
               DBColumnName="likedObj" /> 
 </ClassMap>
</rdb2rdf_sample>