Logical views¶
A logical view (rml:LogicalView, from RML-LV) describes a source as a table. You name the fields once, flatten
nested data, and join other views. Triples maps then refer to fields by name.
Fields¶
A view is defined on a logical source, or on another view, with rml:viewOn. It has two kinds of field:
rml:ExpressionFieldis a named value, from a reference, a template, a constant or a function.rml:IterableFieldis a nested iteration with fields of its own. It produces one row per nested item.
@prefix rml: <http://w3id.org/rml/> .
@prefix : <http://example.org/> .
:jsonSource a rml:LogicalSource ;
rml:source [ a rml:RelativePathSource ; rml:path "people.json" ] ;
rml:referenceFormulation rml:JSONPath ;
rml:iterator "$.people[*]" .
:personView a rml:LogicalView ;
rml:viewOn :jsonSource ;
rml:field [ a rml:ExpressionField ; rml:fieldName "name" ; rml:reference "$.name" ] ;
rml:field [ a rml:IterableField ; rml:fieldName "item" ; rml:iterator "$.items[*]" ;
rml:field [ a rml:ExpressionField ; rml:fieldName "type" ; rml:reference "$.type" ] ] .
Mapping over a view¶
A triples map uses the view as its logical source. References and templates use field names. A field inside an iterable field is addressed with a dot.
:personMap a rml:TriplesMap ;
rml:logicalSource :personView ;
rml:subjectMap [ rml:template "http://example.org/person/{name}/item/{item.type}" ] ;
rml:predicateObjectMap [
rml:predicate :hasItemType ;
rml:objectMap [ rml:reference "item.type" ] ] .
Joins¶
rml:leftJoin and rml:innerJoin join another view. The join names the parent view, the condition, and the parent
fields to bring in under a new name.
:csvSource a rml:LogicalSource ;
rml:source [ a rml:RelativePathSource ; rml:path "people.csv" ] ;
rml:referenceFormulation rml:CSV .
:birthView a rml:LogicalView ;
rml:viewOn :csvSource ;
rml:field [ a rml:ExpressionField ; rml:fieldName "name" ; rml:reference "name" ] ;
rml:field [ a rml:ExpressionField ; rml:fieldName "birthyear" ; rml:reference "birthyear" ] .
:personWithYear a rml:LogicalView ;
rml:viewOn :jsonSource ;
rml:field [ a rml:ExpressionField ; rml:fieldName "name" ; rml:reference "$.name" ] ;
rml:leftJoin [
rml:parentLogicalView :birthView ;
rml:joinCondition [ rml:parent "name" ; rml:child "name" ] ;
rml:field [ a rml:ExpressionField ; rml:fieldName "born" ; rml:reference "birthyear" ] ] .
A triples map on :personWithYear can now use {born}. With a left join, a row without a match keeps its own
fields. With an inner join it is dropped.
Where the join runs depends on the evaluator: in memory for the reactive evaluator, in DuckDB, or in the source database for the native SQL evaluator.
Structural annotations¶
An annotation states a fact about a view's rows that CARML cannot see for itself. CARML uses these facts to skip work.
| Annotation | States |
|---|---|
rml:PrimaryKeyAnnotation |
The fields identify a row and are never null. |
rml:UniqueAnnotation |
No two rows share these field values. |
rml:NotNullAnnotation |
The fields are never null. |
rml:ForeignKeyAnnotation |
The fields match rml:targetFields of a row in rml:targetView. |
rml:InclusionAnnotation |
Like a foreign key, but the target fields need not be unique. |
Added to the two views above:
:birthView
rml:structuralAnnotation [
a rml:PrimaryKeyAnnotation ;
rml:onFields [ a rml:Field ; rml:fieldName "name" ] ] .
:personWithYear
rml:structuralAnnotation [
a rml:ForeignKeyAnnotation ;
rml:onFields [ a rml:Field ; rml:fieldName "name" ] ;
rml:targetView :birthView ;
rml:targetFields [ a rml:Field ; rml:fieldName "name" ] ] .
The logical view pipeline lists what CARML does with them. Deduplication depends on them most.
CARML trusts annotations
CARML does not check an annotation against the data, and acts on it. A left join runs as an inner join when the child's join fields are not null and a foreign key or inclusion annotation maps them to the parent's join fields. If a child row has no match after all, it is dropped. A primary key that is not unique lets duplicates through.