Skip to content

Commit

Permalink
Fix watched properties parameter + README update
Browse files Browse the repository at this point in the history
  • Loading branch information
julianrojas87 committed Nov 20, 2023
1 parent 05c99bb commit 4a6cce4
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 41 deletions.
181 changes: 180 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Bun CI](https://github.com/julianrojas87/rml-mapper-processor-ts/actions/workflows/build-test.yml/badge.svg)](https://github.com/julianrojas87/rml-mapper-processor-ts/actions/workflows/build-test.yml) [![npm](https://img.shields.io/npm/v/rml-mapper-processor-ts.svg?style=popout)](https://npmjs.com/package/rml-mapper-processor-ts)

Typescript wrappers over the RML-related operations to be reused within the [Connector Architecture](hhttps://the-connector-architecture.github.io/site/docs/1_Home). Currently this repository exposes 2 functions:
Typescript wrappers over the RML-related operations to be reused within the [Connector Architecture](hhttps://the-connector-architecture.github.io/site/docs/1_Home). Currently this repository exposes 3 functions:

### [`js:Y2R`](https://github.com/julianrojas87/rml-mapper-processor-ts/blob/main/processors.ttl#L9)

Expand All @@ -15,6 +15,9 @@ This processor is executes RML mapping rules using the Java-based [RMLMapper eng
Logical sources can be marked as trigger-based (`js:trigger`) to indicate that they will be updated in the future and therefore, triggering new mapping executions. Finally, a path (`js:rmlJar`) to a local RMLMapper can be given. An example definition of the processor is shown next:

```turtle
@prefix : <https://w3id.org/conn#>.
@prefix js: <https://w3id.org/conn/js#>.
[ ] a js:RMLMapperReader;
js:rmlSource [
js:sourceLocation "dataset/data.xml";
Expand All @@ -32,3 +35,179 @@ Logical sources can be marked as trigger-based (`js:trigger`) to indicate that t
# js:output <jw>; # This parameter is only needed if no js:rmlTarget are defined
js:rmlJar <./rmlmapper-6.3.0-r0-all.jar>.
```

### [`js:IncRMLTransformer`](https://github.com/julianrojas87/rml-mapper-processor-ts/blob/main/processors.ttl#L142)

This processor transforms a given RML mapping document to a Incremental RML (IncRML) version of itself. Concretely, this means that every defined `rr:TriplesMap` (that has at least 1 defined `rr:predicateObjectMap`) is further expanded into 3 new `rr:TriplesMap`s, each one dedicated to handle entity `create`, `update` and `delete` events. This processor can be used within a CA pipeline as follows:

```turtle
@prefix : <https://w3id.org/conn#>.
@prefix js: <https://w3id.org/conn/js#>.
@prefix idlab-fn: <http://example.com/idlab/function/>.
@prefix as: <https://www.w3.org/ns/activitystreams#>.
@prefix dc: <http://purl.org/dc/terms/>.
@prefix formats: <http://www.w3.org/ns/formats/>.
[ ] a js:IncRMLTransformer;
js:rmlStream <rmlStream>;
js:config [
js:stateBasePath <./state>;
js:lifeCycleConfig [
js:predicate <http://ex.org/lifeCycleProp>;
js:create [
js:function idlab-fn:explicitCreate;
js:type as:Create
];
js:update [
js:function idlab-fn:implicitUpdate;
js:type as:Update
];
js:delete [
js:function idlab-fn:implicitDelete;
js:type as:Delete
]
];
js:targetConfig [ # LDES-based target configuration is optional
js:targetPath <./output.nt>;
js:timestampPath dc:modified;
js:versionOfPath dc:isVersionOf;
js:serialization formats:N-Triples;
js:uniqueIRIs true;
js:ldesBaseIRI <http://ex.org/my-ldes>;
js:shape <http://ex.org/my-ldes/shape>
]
];
js:incrmlStream <incrmlStream>;
js:bulkMode true. # Optional, to handle multiple mapping files together
```

The configuration (`js:config`) of the processor includes a specification of the predicate (`js:lifeCycleConfig/js:predicate`) that will be used to characterize entities and the particular FnO functions that will be used to detect create, update and delete events.

Optionally, a LDES-based logical target configuration (`js:targetConfig`) can be given to produce unique IRIs for every entity and LDES-specific metadata.

Taking for example, the above processor configuration and the following RML mapping as input:

```turtle
<http://ex.org/m0> a rr:TriplesMap ;
rml:logicalSource [
a rml:LogicalSource ;
rml:source "data.xml" ;
rml:iterator "//Data" ;
rml:referenceFormulation ql:XPath
] ;
rr:subjectMap [
a rr:SubjectMap ;
rr:template "http://ex.org/instance/{prop1/@value}" ;
rr:class "http://ex.org/ns/SomeClass" ;
] ;
rr:predicateObjectMap [
rr:predicate "http://ex.org/ns/someProperty" ;
rr:objectMap [
rml:reference "prop2/@value"
]
] .
```

The processor will expand the mapping to the following IncRML document:

```turtle
<http://ex.org/m0_create> a rr:TriplesMap ; # Create event
rml:logicalSource _:bn0 ;
rr:subjectMap [
a rr:FunctionTermMap ;
fnml:functionValue [
rr:predicateObjectMap [
rr:predicate fno:executes ;
rr:objectMap [ rr:constant idlab-fn:explicitCreate ]
], [
rr:predicate idlab-fn:iri ;
rr:objectMap [ rr:template "http://ex.org/instance/{prop1/@value}" ]
], [
rr:predicate idlab-fn:state ;
rr:objectMap [ rr:constant "./state/3cd43073163c2153e4f6b01788350e0d_create_state" ]
]
] ;
rml:logicalTarget _:bn1
] ;
rr:predicateObjectMap _:bn2 ;
rr:predicateObjectMap [
rr:predicate <http://ex.org/lifeCycleProp> ;
rr:objectMap [ rr:constant as:Create ]
] .
<http://ex.org/m0_update> a rr:TriplesMap ; # Update event
rml:logicalSource _:bn0 ;
rr:subjectMap [
a rr:FunctionTermMap ;
fnml:functionValue [
rr:predicateObjectMap [
rr:predicate fno:executes ;
rr:objectMap [ rr:constant idlab-fn:implicitUpdate ]
], [
rr:predicate idlab-fn:iri ;
rr:objectMap [ rr:template "http://ex.org/instance/{prop1/@value}" ]
], [
rr:predicate idlab-fn:watchedProperties ;
rr:objectMap [ rr:template "prop0={prop1/@value}" ]
], [
rr:predicate idlab-fn:state ;
rr:objectMap [ rr:constant "./state/957ab073163c2153e4f6b01788323ab42_update_state" ]
]
] ;
rml:logicalTarget _:bn1
] ;
rr:predicateObjectMap _:bn2 ;
rr:predicateObjectMap [
rr:predicate <http://ex.org/lifeCycleProp> ;
rr:objectMap [ rr:constant as:Update ]
] .
<http://ex.org/m0_delete> a rr:TriplesMap ; # Delete event
rml:logicalSource _:bn0 ;
rr:subjectMap [
a rr:FunctionTermMap ;
fnml:functionValue [
rr:predicateObjectMap [
rr:predicate fno:executes ;
rr:objectMap [ rr:constant idlab-fn:implicitDelete ]
], [
rr:predicate idlab-fn:iri ;
rr:objectMap [ rr:template "http://ex.org/instance/{prop1/@value}" ]
], [
rr:predicate idlab-fn:state ;
rr:objectMap [ rr:constant "./state/67af43039445c2153e4f3920a788350fff3_delete_state" ]
]
] ;
rml:logicalTarget _:bn1
] ;
rr:predicateObjectMap [
rr:predicate <http://ex.org/lifeCycleProp> ;
rr:objectMap [ rr:constant as:Delete ]
] .
_:bn0 a rml:LogicalSource ;
rml:source "data.xml" ;
rml:iterator "//Data" ;
rml:referenceFormulation ql:XPath .
_:bn1 a rmlt:EventStreamTarget ; # LDES-based Logical Target
rmlt:target [
a void:Dataset ;
void:dataDump "./output.nt"
] ;
rmlt:ldes [
a ldes:EventStream ;
ldes:timestampPath dc:modified ;
ldes:versionOfPath dc:isVersionOf ;
tree:shape <http://ex.org/my-ldes/shape>
] ;
rmlt:serialization formats:N-Triples ;
rmlt:ldesGenereateImmutableIRI true ;
rmlt:ldesBaseIRI <http://ex.org/my-ldes> .
_:bn2 a rr:PredicateObjectMap ;
rr:predicate "http://ex.org/ns/someProperty" ;
rr:objectMap [
rml:reference "prop2/@value"
] .
```
5 changes: 3 additions & 2 deletions src/rml/incrml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ function generateTriplesMapQuads(
literal(ldesTargetConfig.uniqueIRIs.toString(), namedNode(XSD.custom("boolean")))
),
quad(LDES_LT, RMLT.terms.ldes, LDES_TARGET),
quad(LDES_TARGET, RDF.terms.type, LDES.terms.EventStream),
quad(FTM, RML.terms.logicalTarget, LDES_LT)
]);
// Optional rmlt:ldesBaseIRI
Expand Down Expand Up @@ -501,14 +502,14 @@ function generateTriplesMapQuads(

let c = 0;
propExpressions.forEach(prop => {
wpTemplate.push(`prop${c}=${prop}`);
wpTemplate.push(`prop${c}={${prop}}`);
c++;
});
newTMQuads.push(...[
quad(FV, RR.terms.predicateObjectMap, WATCHED_POM),
quad(WATCHED_POM, RR.terms.predicate, IDLAB_FN.terms.watchedProperty),
quad(WATCHED_POM, RR.terms.objectMap, WATCHED_OM),
quad(WATCHED_OM, RML.terms.reference, literal(wpTemplate.join("&")))
quad(WATCHED_OM, RR.terms.template, literal(wpTemplate.join("&")))
]);
}

Expand Down
Loading

0 comments on commit 4a6cce4

Please sign in to comment.