<img src="https://rml-star.goatcounter.com/count?p=/test-noscript">

RML-star

Draft Community Group Report

Latest editor's draft:
https://w3id.org/kg-construct/rml-star
Editors:
(Ghent University – imec – IDLab)
(Ontology Engineering Group – Universidad Politécnica de Madrid)
(Ontology Engineering Group – Universidad Politécnica de Madrid)
(Ghent University – imec – IDLab)
(Ontology Engineering Group – Universidad Politécnica de Madrid)
This Version
https://kg-construct.github.io/rml-star-spec/20210706/
Previous Version
https://kg-construct.github.io/rml-star-spec/20210706/
Website
https://rml.io/

Abstract

RML-star is an extension of RML designed for expressing customized mappings from heterogeneous data structures and serializations to RDF-star. Such mappings describe how existing data can be represented using RDF-star.

This document describes RML-star through definitions and examples.

The version of this document is Unreleased.

Status of This Document

This specification was published by the Knowledge Graph Construction Community Group. It is not a W3C Standard nor is it on the W3C Standards Track. Please note that under the W3C Community Contributor License Agreement (CLA) there is a limited opt-out and other conditions apply. Learn more about W3C Community and Business Groups.

This is an early draft, yet efforts are made to keep things stable.

1. Overview

This section is non-normative.

RDF-star [RDF-star] is an extension of the Resource Description Framework (RDF) [RDF11-Concepts]. RDF covers triples that are built from three terms: subject, predicate and object, and each term is either an IRI, a blank node or a literal. RDF-star adds a fourth kind of term: the RDF-star triple. With RDF-star, it is possible to represent metadata about individual triples.

# This RDF-star example says that the triple ( :Alice a :Person ) is 80% likely to be true
<< :Alice a :Person >> :confidence 0.8 .

RDF-star distinguishes between different types of RDF-star triples: depending on where a triple occurs, it can be either an asserted triple, an embedded triple, or both asserted and embedded. For a given RDF-star graph, i.e., a for a given set of RDF-star triples, an asserted triple is a triple that is an element of the graph. An embedded triple is a triple that occurs as the subject or object of another triple.

The RDF Mapping Language (RML) [RML] is a language for expressing mappings between heterogeneous data and RDF. In RML, rules can be expressed to iterate over a data source and refer to specific data within an iteration. Using these iterators and references, RML rules define how to express data in the data source in RDF.

This document describes RML-star: an extension of RML that enables the generation of RDF-star triples with RML.

1.1 Conformance

As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.

1.2 Document conventions

We assume readers have basic familiarity with RDF, RML and RDF-star concepts.

In this document, examples assume the following namespace prefix bindings unless otherwise stated:

Prefix Namespace
rml: http://semweb.mmlab.be/ns/rml#
rr: http://www.w3.org/ns/r2rml#
xsd: http://www.w3.org/2001/XMLSchema#
ex: http://example.org/
: http://example.org/

The examples are contained in color-coded boxes. We use the Turtle syntax [Turtle] to write RDF and the Turtle-star syntax [RDF-star] to write RDF-star.

# This box contains an example input
# This box contains an example mapping
# This box contains the example output

2. The RML-star vocabulary

RML-star extends the RML vocabulary by introducing three new classes, three object properties and by modifying one object property.

Classes

Object Properties

2.1 Overview of RML-star terms

The new terms are summarized in the following tables.

Property Domain Range
rml:embeddedTriplesMap rr:StarMap rml:TriplesMap
rr:subjectMap rr:TriplesMap Union of rr:SubjectMap, rml:StarMap
rr:objectMap rr:TriplesMap Union of rr:ObjectMap, rr:RefObjMap, rml:StarMap
Class Superclass
rml:StarMap rr:TermMap
rml:NonAssertedTriplesMap rr:TriplesMap

In certain cases, a join is needed to generate embedded triples. To achieve this, the domain of the property rr:joinCondition is changed. We summarize the change in the following table.

Property Old domain New domain
rr:joinCondition rr:RefObjMap Union of rr:RefObjMap, rml:StarMap

All RML-star additions and changes to RML are shown in this diagram:

Target structure
Figure 1 To enable the generation of RDF-star graphs, RML-star adds three properties and two classes to the RML ontology, and changes the domain of one property.

3. Generating embedded triples with RML-star

A star map (rml:StarMap) is a term map that generates embedded triples. It can be used in the subject map and object map positions. A star map has is linked to a triples map by the embedded triples map property (rml:embeddedTriplesMap). The embedded triples generated by a star map are exactly those triples generated by its embedded triples map. If a star map has the same logical source as its embedded triples map then for each logical iteration the embedded triples generated by a star map are those triples generated by its embedded triples map for the same logical iteration. If a star map has a different logical source than its embedded triples map then a join is used, as described in the next section.

In the following example, per logical iteration, i.e., per CSV row, a "type" triple is generated by :innerTriplesMap that occurs in the resulting graph both as an asserted and as an embedded triple:

# contents of the :confidence logical source
entity,class,confidence
Alice,Person,0.8
Bobby,Dog,0.6
# triples map that generates "type" triples
:innerTriplesMap a rr:TriplesMap ;
  rml:logicalSource :confidence ;
  rml:subjectMap [ rr:template "http://example.com/{entity}" ] ;
  rr:predicateObjectMap [
    rr:predicate rdf:type ;
    rml:objectMap [ rr:template "http://example.com/{class}" ] ] .
    
# triples map that generates "confidence" triples
:outerTriplesMap a rr:TriplesMap ;
  rml:logicalSource :confidence ;
  rml:subjectMap [ rml:embeddedTriplesMap :innerTriplesMap ] ;
  rr:predicateObjectMap [
    rr:predicate :confidence ;
    rml:objectMap [ 
      rml:reference "confidence" ;
      rr:termType xsd:float ] ] .
# Triples generated by :innerTriplesMap
:Alice a :Person .
:Bobby a :Dog .

# Triples generated by :outerTriplesMap
<< :Alice a :Person >> :confidence 0.8 .
<< :Bobby a :Dog >> :confidence 0.6 .

By default, triples generated by a triples map are generated as asserted triples. If the triples map is also used in a star map, the triples it generates also occur in the resulting graph as embedded triples, by the process explained in the previous paragraph. The generation of asserted triples by a triples map can be supressed by declaring it an non-asserted triples map (rml:NonAssertedTriplesMap), a subclass of rr:TriplesMap. A triples map of subclass non-asserted triples map does not generate asserted triples, but might generate embedded triples if it is used in a star map. A summary of how to generate triples in any combination of asserted and/or embedded is given in the following table, where rr:TriplesMap refers to instances of rr:TriplesMap that are not of the rml:NonAssertedTriplesMap subclass:

Embedded Not embedded
Asserted rr:TriplesMap with rml:StarMap rr:TriplesMap without rml:StarMap
Not asserted rml:NonAssertedTriplesMap with rml:StarMap rml:NonAssertedTriplesMap without rml:StarMap

The following example is different than the previous in that :innerTriplesMap is declared to be an instance of rml:NonAssertedTriplesMap, with the effect that the generated "type" triples are only present in the resulting graph as embedded triples, not as asserted triples:

# contents of the :confidence logical source
entity,class,confidence
Alice,Person,0.8
Bobby,Dog,0.6
# triples map that generates "type" triples
:innerTriplesMap a rml:NonAssertedTriplesMap ;
  rml:logicalSource :confidence ;
  rml:subjectMap [ rr:template "http://example.com/{entity}" ] ;
  rr:predicateObjectMap [
    rr:predicate rdf:type ;
    rml:objectMap [ rr:template "http://example.com/{class}" ] ] .
    
# triples map that generates "confidence" triples
:outerTriplesMap a rr:TriplesMap ;
  rml:logicalSource :CSVLogicalSource ;
  rml:subjectMap [ rml:embeddedTriplesMap :innerTriplesMap ] ;
  rr:predicateObjectMap [
    rr:predicate :confidence ;
    rml:objectMap [ 
      rml:reference "confidence" ;
      rr:termType xsd:float ] ] .
<< :Alice a :Person >> :confidence 0.8 .
<< :Bobby a :Dog >> :confidence 0.6 .

4. Generating embedded triples from multiple sources

RML-star can create RDF-star triples from multiple logical sources. When creating RDF-star triples from multiple logical sources, join conditions are used, just like when using referencing object maps in RML.

If a star map has a join condition, it generates embedded triples as follows. Each combination of iterations, i.e., the Cartesian product, from the child source and the parent source is looked at. Here, we consider as child source the logical source of the triples map in which the star map occurs, and as parent source the logical source of the star map's embedded triples map. A star map only generates embedded triples for combinations in which the join condition holds true. As is the case when join conditions are used in in referencing object maps, a join condition checks for equality of the reference values of the child/parent reference between iterations of the child/parent source.

If the logical source of triples map in which a star map occurs and the logical source of star map's embedded triples map are not identical, then the star map must have at least one join condition.

# contents of logical source :classes
entity,class
Alice,Person
Bobby,Dog
# contents of logical source :confidences
entity,confidence
Alice,0.8
Bobby,0.6
# triples map that generates "type" triples
:innerTriplesMap a rml:NonAssertedTriplesMap ;
  rml:logicalSource :classes ;
  rml:subjectMap [ rr:template "http://example.com/{entity}" ] ;
  rr:predicateObjectMap [
    rr:predicate rdf:type ;
    rml:objectMap [ rr:template "http://example.com/{class}" ] ] .
    
# triples map that generates "confidence" triples
:outerTriplesMap a rr:TriplesMap ;
  rml:logicalSource :confidences ;
  rml:subjectMap [ 
    rml:embeddedTriplesMap :innerTriplesMap
    rr:joinCondition [
        rr:parent "entity" ;
        rr:child "entity" ] ] ;
  rr:predicateObjectMap [
    rr:predicate :confidence ;
    rml:objectMap [ 
      rml:reference "confidence" ;
      rr:termType xsd:float ] ] .
<< :Alice a :Person >> :confidence 0.8 .
<< :Bobby a :Dog >> :confidence 0.6 .

4.1 Using star map together with referencing object maps

It is also possible to generate embedded triples which themselves are built from multiple sources. This is done by using an embedded triples map which contains a referencing object map.

Note: this process for generating embedded triples with a referencing object map is not different from the general process to create embedded triples described earlier, but we include this section for clarity.

# contents of logical source :classes
entity,class
Alice,Person
Bobby,Dog
# contents of logical source :confidences
entity,confidence
Alice,0.8
Bobby,0.6
# triples map that generates objects of "type" triples
:classTriplesMap a rr:TriplesMap ;
  rml:logicalSource :classes ;
  rml:subjectMap [ rr:template "http://example.com/{class}" ].

# triples map that generates "type" triples using a join
:innerTriplesMap a rml:NonAssertedTriplesMap ;
  rml:logicalSource :confidences ;
  rml:subjectMap [ rr:template "http://example.com/{entity}" ] ;
  rr:predicateObjectMap [
    rr:predicate rdf:type ;
    rml:objectMap [ 
      rr:parentTriplesMap :classTriplesMap ;
      rr:joinCondition [
        rr:parent "entity" ;
        rr:child "entity" ] ] ] .
    
# triples map that generates "confidence" triples
:outerTriplesMap a rr:TriplesMap ;
  rml:logicalSource :confidences ;
  rml:subjectMap [ rml:embeddedTriplesMap :innerTriplesMap ] ;
  rr:predicateObjectMap [
    rr:predicate :confidence ;
    rml:objectMap [ 
      rml:reference "confidence" ;
      rr:termType xsd:float ] ] .
<< :Alice a :Person >> :confidence 0.8 .
<< :Bobby a :Dog >> :confidence 0.6 .

5. Generating deeply nested embedded triples

It is possible to create more deeply nested RDF-star by using an embedded triples map that on its own turn also uses an embedded triples map.

Note: this process for generating deeply nested embedded triples is not different from the general process to create embedded triples described earlier, but we include this section for clarity.

# contents of logical source :predictions
entity,class,confidence,predictor
Alice,Person,0.8,alpha
Alice,Giraffe,1.0,alpha
Bobby,Dog,0.6,alpha
Bobby,Giraffe,1.0,beta
# triples map that generates "type" triples
:innerTriplesMap a rml:NonAssertedTriplesMap ;
  rml:logicalSource :predictions ;
  rml:subjectMap [ rr:template "http://example.com/{entity}" ] ;
  rr:predicateObjectMap [
    rr:predicate rdf:type ;
    rml:objectMap [ rr:template "http://example.com/{class}" ] ] ] .
        
# triples map that generates "confidence" triples
:middleTriplesMap a rml:NonAssertedTriplesMap ;
  rml:logicalSource :predictions ;
  rml:subjectMap [ rml:embeddedTriplesMap :innerTriplesMap ] ;
  rr:predicateObjectMap [
    rr:predicate :confidence ;
    rml:objectMap [ 
      rml:reference "confidence" ;
      rr:termType xsd:float ] ] .
    
# triples map that generates "predicted by" triples
:outerTriplesMap a rr:TriplesMap ;
  rml:logicalSource :predictions ;
  rml:subjectMap [ rml:embeddedTriplesMap :middleTriplesMap ] ;
  rr:predicateObjectMap [
    rr:predicate :predictedBy ;
    rml:objectMap [ rr:template "http://example.com/{predictor}" ] ] .
<< << :Alice a :Person >> :confidence 0.8 >> :predictedBy :alpha .
<< << :Alice a :Giraffe >> :confidence 1.0 >> :predictedBy :beta .
<< << :Bobby a :Dog >> :confidence 0.6 >> :predictedBy :alpha .
<< << :Bobby a :Giraffe >> :confidence 1.0 >> :predictedBy :beta .

A. References

A.1 Informative references

[RDF-star]
RDF-star and SPARQL-star. W3C. 13 April 2021. Community Group Draft. URL: https://w3c.github.io/rdf-star/cg-spec/
[RDF11-Concepts]
RDF 1.1 Concepts and Abstract Syntax. W3C. 25 February 2014. W3C Recommendation. URL: https://www.w3.org/TR/rdf11-concepts/
[RML]
RDF Mapping Language. https://rml.io. 06 October 2020. Unofficial draft. URL: https://rml.io/specs/rml/
[Turtle]
RDF 1.1 Turtle. W3C. 25 February 2014. W3C Recommendation. URL: https://www.w3.org/TR/turtle/