Last active
March 23, 2018 20:30
-
-
Save alpox/88fa8ba7ac298c9080ca40828791b4b0 to your computer and use it in GitHub Desktop.
enricher
This file contains hidden or 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
const { transformFactory } = require('../utils/stream'); | |
const { GENERATED_AT_TIME } = require('../utils/constants'); | |
module.exports = transformFactory((stream, config, transform) => data => { | |
const transformed = transform(data); | |
const id = transformed[0].subject; | |
const graph = transformed.reduce( | |
(acc, triple) => { | |
acc[triple.predicate] = { '@id': triple.object }; | |
return acc; | |
}, | |
{ '@id': id } | |
); | |
stream.push({ | |
'@id': id, | |
'@graph': graph, | |
[GENERATED_AT_TIME]: new Date() | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment