RML Transformations

The RDF Mapping Language (RML) is an ETL configuration language for linked data. RML mappings are applied to the TriplyETL Record.

Configuration components

RML mappings contain the following configuration components:

  • Logical Source: Defines the source of the data to be transformed. It includes information about the data format (csv, xml, json, etc.), location, and access methods. Logical sources can represent various types of data sources, such as files, databases, or web services.

  • Triples Map: The mapping rules that are used to convert data from a Logical Source to linked data. It defines how data should be transformed and specifies the subject, predicate and object terms of the generated statements.

    • Subject Map: The part of the Triples Map that defines how the subjects of the generated linked data statements must be constructed. It specifies the subject's term type, which can be blank node, IRI or literal. It often includes the class of which the subject term is an instance.

    • Predicate Object Map: The part of the Triples Map that defines how the predicate and objects are mapped.

A simple example

The following full TriplyETL script applies the RML mappings specified in map.trig to the in-line specified source data record:

import { logQuads } from '@triplyetl/etl/debug'
import { Etl, fromJson, Source } from '@triplyetl/etl/generic'
import { map } from '@triplyetl/etl/rml'

export default async function (): Promise<Etl> {
  const etl = new Etl()
  etl.use(
    fromJson([{ name: 'John' }]),
    map(Source.file('map.trig')),
    logQuads(),
  )
  return etl
}

The contents of file map.trig specify how the data will be mapped:

prefix ql: <http://semweb.mmlab.be/ns/ql#>
prefix rml: <http://semweb.mmlab.be/ns/rml#>
prefix rr: <http://www.w3.org/ns/r2rml#>
prefix sdo: <https://schema.org/>

[] rml:logicalSource
     [ rml:source '$Record.json';
       rml:referenceFormulation ql:JSONPath;
       rml:iterator '$' ];
   rr:subjectMap
     [ rr:termType rr:BlankNode;
       rr:class sdo:Person ];
   rr:predicateObjectMap
     [ rr:predicate sdo:firstName;
       rr:objectMap [ rml:reference 'name' ] ].

The Logical Source component specifies that the TriplyETL Record should be used:

[] rml:logicalSource
     [ rml:source '$Record.json';
       rml:referenceFormulation ql:JSONPath;
       rml:iterator '$' ];

The Subject Map specifies that the subject term is a blank node that is an instance of class sdo:Person:

[] rr:subjectMap
     [ rr:termType rr:BlankNode;
       rr:class sdo:Person ];

The Predicate Object Map specifies that the value of key 'name' should be used together with the property sdo:firstName:

[] rr:predicateObjectMap
     [ rr:predicate sdo:firstName;
       rr:objectMap [ rml:reference 'name' ] ].

Running the TriplyETL script results in the following linked data:

<https://triplydb.com/.well-known/genid/1703545835347b1_b0>
  a sdo:Person;
  sdo:firstName 'John'.