-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter deltas: Add rdflib.js and class Delta
Class Delta from: https://github.com/lblod/toezicht-flattened-form-data-generator/blob/v1.3.0/lib/delta.js
- Loading branch information
1 parent
f7e03f8
commit 15ac139
Showing
5 changed files
with
2,416 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { NamedNode, triple } from 'rdflib'; | ||
|
||
export class Delta { | ||
constructor(delta) { | ||
this.delta = delta; | ||
} | ||
|
||
get inserts() { | ||
return this.delta.map((changeSet) => changeSet.inserts).flat(); | ||
} | ||
|
||
getInsertsFor(trigger) { | ||
return this.inserts | ||
.filter((triple) => this.isTriggerTriple(triple, trigger)) | ||
.map(this.mapToRdfTriple); | ||
} | ||
|
||
isTriggerTriple(triple, trigger) { | ||
return ( | ||
triple.predicate.value === trigger.predicate.value && | ||
triple.object.value === trigger.object.value | ||
); | ||
} | ||
|
||
mapToRdfTriple(t) { | ||
return triple( | ||
new NamedNode(t.subject.value), | ||
new NamedNode(t.predicate.value), | ||
new NamedNode(t.object.value), | ||
); | ||
} | ||
} |
Oops, something went wrong.