Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Within this part of the user documentation we have provided a wide array of sample mapping files to aid you in the creation of your own.

Table of Contents

Page Structure

As with the Manually Create a Mapping File document, the examples will be clearly displayed using the following colour codes. Please note all Provenance Named Graphs have been omitted for simplicity and therefore the RDF output will be represented in NTtriples.

Code Block
RML mapping files will be blue
Code Block
Example input data will be yellow
Code Block
Output RDF triples will be green 

Example 1 - Simple CSV

Code Block
@prefix rr:  <http://www.w3.org/ns/r2rml#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ql:  <http://semweb.mmlab.be/ns/ql#> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix ex:  <http://example.com/> .

@base <http://example.com/base/> .

<TriplesMap1>
  a rr:TriplesMap;

  rml:logicalSource [
    rml:source "inputSourceFile.csv";
    rml:referenceFormulation ql:CSV
  ];

  rr:subjectMap [
    rr:template "http://example.com/{id}";
    rr:class ex:Employee
  ];

  rr:predicateObjectMap [
    rr:predicate ex:hasName;
    rr:objectMap [
      rr:template "{name}";
      rr:termType rr:Literal;
      rr:datatype xsd:string
    ]
  ].

id

name

10001

Alice

10002

Bob

Code Block
<http://example.com/10001> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/Employee> .
<http://example.com/10001> <http://example.com/hasName> "Alice" .
<http://example.com/10002> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/Employee> .
<http://example.com/10002> <http://example.com/hasName> "Bob" .

 

Example 2 - Simple JSON

Code Block
@prefix rr:  <http://www.w3.org/ns/r2rml#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ql:  <http://semweb.mmlab.be/ns/ql#> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix ex:  <http://example.com/> .

@base <http://example.com/base/> .

<TriplesMap1>
  a rr:TriplesMap;

  rml:logicalSource [
    rml:source "inputSourceFile.json";
    rml:referenceFormulation ql:JSONPath;
	rml:iterator "$.employees.[*]"
  ];

  rr:subjectMap [
    rr:template "http://example.com/{id}";
    rr:class ex:Employee
  ];

  rr:predicateObjectMap [
    rr:predicate ex:hasName;
    rr:objectMap [
      rr:template "{name}";
      rr:termType rr:Literal;
      rr:datatype xsd:string
    ]
  ].
Code Block
languagejson
{
  employees: [
    {
      id: 10001,
      name: Alice
    },
    {
      id: 10002,
      name: Bob
    }
  ]
}

Code Block
<http://example.com/10001> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/Employee> .
<http://example.com/10001> <http://example.com/hasName> "Alice" .
<http://example.com/10002> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/Employee> .
<http://example.com/10002> <http://example.com/hasName> "Bob" .

 

Example 3 - Simple XML

Code Block
@prefix rr:  <http://www.w3.org/ns/r2rml#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ql:  <http://semweb.mmlab.be/ns/ql#> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix ex:  <http://example.com/> .

@base <http://example.com/base/> .

<TriplesMap1>
  a rr:TriplesMap;

  rml:logicalSource [
    rml:source "inputSourceFile.xml";
    rml:referenceFormulation ql:SaXPath;
    rml:iterator "/employees/employee"
  ];

  rr:subjectMap [
    rr:template "http://example.com/{@id}";
    rr:class ex:Employee
  ];

  rr:predicateObjectMap [
    rr:predicate ex:hasName;
    rr:objectMap [
      rr:template "{firstname} {lastname}";
      rr:termType rr:Literal;
      rr:datatype xsd:string
    ]
  ].
Code Block
languagexml
<?xml version="1.0" encoding="UTF-8"?>
<employees>
  <employee id="10001">
	<firstname>Alice</firstname>
	<lastname>Johnson</lastname>
  </employee>
  <employee id="10002">
	<firstname>Bob</firstname>
	<lastname>Smith</lastname>
  </employee>
</employees>

Code Block
<http://example.com/10001> <http://example.com/hasName> "Alice Johnson" .
<http://example.com/10001> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/Employee> .
<http://example.com/10002> <http://example.com/hasName> "Bob Smith" .
<http://example.com/10002> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/Employee> .

 

Example 4 - Simple SQL

Code Block
@prefix rr:  <http://www.w3.org/ns/r2rml#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ql:  <http://semweb.mmlab.be/ns/ql#> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix ex:  <http://example.com/> .
@prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#> .
@prefix jdbc: <http://d2rq.org/terms/jdbc/> .

@base <http://example.com/base/> .

<TriplesMap1>
  a rr:TriplesMap;
    
  rml:logicalSource [ 
    rml:source <#DB_source>;
    rr:sqlVersion rr:SQL2008;
    rr:tableName "employees";
  ];

  rr:subjectMap [ 
    rr:template "http://example.com/{id}"
  ]; 
	
  rr:predicateObjectMap [ 
    rr:predicate ex:name; 
    rr:objectMap [
      rr:template "{firstname}_{lastname}";
      rr:termType rr:Literal;
      rr:datatype xsd:string
    ]
  ].

										
<#DB_source> a d2rq:Database;
  d2rq:jdbcDSN "jdbc:mysql://localhost:3306/employees";
  d2rq:jdbcDriver "com.mysql.cj.jdbc.Driver";
  d2rq:username "";
  d2rq:password "".

id

firstname

lastname

occupation

10001

Alice

Johnson

Tech

10002

Bob

Smith

Sales

Code Block
<http://example.com/10001> <http://example.com/name> "Alice_Johnson" .
<http://example.com/10002> <http://example.com/name> "Bob_Smith" .

Example 5 - Simple SQL with Query

Code Block
@prefix rr:  <http://www.w3.org/ns/r2rml#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ql:  <http://semweb.mmlab.be/ns/ql#> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix ex:  <http://example.com/> .
@prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#> .
@prefix jdbc: <http://d2rq.org/terms/jdbc/> .

@base <http://example.com/base/> .

<TriplesMap1>
  a rr:TriplesMap;
    
  rml:logicalSource [ 
    rml:source <#DB_source>;
    rr:sqlVersion rr:SQL2008;
    rml:query """
        SELECT id,
               firstname,
               lastname,
               (CHAR_LENGTH(firstname)) AS namelength
        FROM employees;
    """;
    rml:referenceFormulation ql:CSV
  ];

  rr:subjectMap [ 
    rr:template "http://example.com/{id}"
  ]; 
  
  rr:predicateObjectMap [ 
    rr:predicate ex:name; 
    rr:objectMap [
      rr:template "{firstname}_{lastname}";
      rr:termType rr:Literal;
      rr:datatype xsd:string
    ]
  ];

  rr:predicateObjectMap [ 
    rr:predicate ex:namelength; 
    rr:objectMap [
      rr:template "{namelength}";
      rr:termType rr:Literal;
      rr:datatype xsd:int
    ]
  ].
           
<#DB_source> a d2rq:Database;
  d2rq:jdbcDSN "jdbc:mysql://localhost:3306/employees";
  d2rq:jdbcDriver "com.mysql.cj.jdbc.Driver";
  d2rq:username "";
  d2rq:password "".

id

firstname

lastname

occupation

10001

Alice

Johnson

Tech

10002

Bob

Smith

Sales

Code Block
<http://example.com/10001> <http://example.com/name> "Alice_Johnson" .
<http://example.com/10001> <http://example.com/namelength> "5"^^<http://www.w3.org/2001/XMLSchema#int> .
<http://example.com/10002> <http://example.com/name> "Bob_Smith" .
<http://example.com/10002> <http://example.com/namelength> "3"^^<http://www.w3.org/2001/XMLSchema#int> .

Example 6 - Function within a Subject Map

Code Block
@prefix rr:  <http://www.w3.org/ns/r2rml#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ql:  <http://semweb.mmlab.be/ns/ql#> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix ex:  <http://example.com/> .
@prefix fnml: <http://semweb.mmlab.be/ns/fnml#> .
@prefix fno: <https://w3id.org/function/ontology#> .
@prefix grel: <http://users.ugent.be/~bjdmeest/function/grel.ttl#> .
@prefix idlab-fn: <http://example.com/idlab/function/> .

@base <http://graph.build/> .

<TriplesMap1>
  a rr:TriplesMap;

  rml:logicalSource [
    rml:source "inputSourceFile.csv";
    rml:referenceFormulation ql:CSV
  ];

  rr:subjectMap [
    fnml:functionValue [
      rr:predicateObjectMap [
        rr:predicate fno:executes ;
        rr:objectMap [ rr:constant grel:toUpperCase ]
      ] ;
      rr:predicateObjectMap [
        rr:predicate grel:valueParameter ;
        rr:objectMap [ rr:template "http://example.com/{id}" ]
      ]
    ] ;
    rr:class ex:Person
  ];

  rr:predicateObjectMap [
    rr:predicate ex:name ;
    rr:objectMap [
      rml:reference "name";      
      rr:termType rr:Literal ;
      rr:datatype xsd:string
    ]
  ] .

id

name

10001

Alice

10002

Bob

Code Block
<HTTP://EXAMPLE.COM/10001> <http://example.com/name> "Alice" .
<HTTP://EXAMPLE.COM/10001> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/Person> .
<HTTP://EXAMPLE.COM/10002> <http://example.com/name> "Bob" .
<HTTP://EXAMPLE.COM/10002> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/Person> .

 

Example 7 - Complex Embedded Functions

In this example we are using embedded function, functions within functions. We start with an if then else function where if the input contains the text “NIS“, split the input at the underscore (_), else split the input at the forward slash (/).

Code Block
@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ql: <http://semweb.mmlab.be/ns/ql#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix ex: <http://example.com/> .
@prefix fnml: <http://semweb.mmlab.be/ns/fnml#> .
@prefix fno: <https://w3id.org/function/ontology#> .
@prefix grel: <http://users.ugent.be/~bjdmeest/function/grel.ttl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.

@base <http://graph.build/> .

<#product> a rr:TriplesMap ;
 
  rml:logicalSource [
    rml:source "inputSourceFile.csv" ;
    rml:referenceFormulation ql:CSV
  ] ;
 
  rr:subjectMap [
    fnml:functionValue [
      rr:predicateObjectMap [
        rr:predicate fno:executes ;
        rr:objectMap [ rr:constant grel:controls_if ]
      ] ;

      rr:predicateObjectMap [
          rr:predicate grel:bool_b ;
          rr:objectMap <#ERPSource>
      ];

      rr:predicateObjectMap [
        rr:predicate grel:any_true ;
        rr:objectMap <#DelimitUnderscore>
      ] ;
     
      rr:predicateObjectMap [
        rr:predicate grel:any_false ;
        rr:objectMap <#DelimitSlash>
      ]
    ] ;
    rr:class ex:Product
  ] .
 
  <#ERPSource>
    fnml:functionValue [
      rr:predicateObjectMap [
          rr:predicate fno:executes ;
          rr:objectMap [ rr:constant grel:string_contains ]
      ];

      rr:predicateObjectMap [
        rr:predicate grel:valueParameter ;
        rr:objectMap [ rml:reference "source_id" ]
      ];
     
      rr:predicateObjectMap [
        rr:predicate grel:string_sub ;
        rr:objectMap [ rr:constant "NIS" ]
      ]
    ].

  <#DelimitUnderscore>
    fnml:functionValue [
      rr:predicateObjectMap [
          rr:predicate fno:executes ;
          rr:objectMap [ rr:constant grel:string_split ]
      ];

      rr:predicateObjectMap [
        rr:predicate grel:valueParameter ;
        rr:objectMap [ rml:reference "source_id" ]
      ];
     
      rr:predicateObjectMap [
        rr:predicate grel:p_string_sep ;
        rr:objectMap [ rr:constant "_" ]
      ]
    ].

  <#DelimitSlash>
    fnml:functionValue [
      rr:predicateObjectMap [
          rr:predicate fno:executes ;
          rr:objectMap [ rr:constant grel:string_split ]
      ];

      rr:predicateObjectMap [
        rr:predicate grel:valueParameter ;
        rr:objectMap [ rml:reference "source_id" ]
      ];
     
      rr:predicateObjectMap [
        rr:predicate grel:p_string_sep ;
        rr:objectMap [ rr:constant "/" ]
      ]
    ].

source_id

CTM16X00-LUZ-K-S/04/0001

580338M3_SURM3_BASE

121951W9MLXNISDTAUSUS_77NISDTAUSUS_0001

Code Block
<http://graph.build/121951W9MLXNISDTAUSUS> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/Product> .
<http://graph.build/580338M3_SURM3_BASE> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/Product> .
<http://graph.build/CTM16X00-LUZ-K-S> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/Product> .