Created
July 24, 2019 03:13
-
-
Save howarddierking/a2e23aca0c731f176e0240e39c5000fe to your computer and use it in GitHub Desktop.
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
'use strict'; | |
const R = require('ramda'); | |
const Rx = require('../ramdaExt'); | |
const concatUnique = (k, l, r) => { | |
if(R.equals(l, r)) | |
return R.flatten([l]); | |
return R.flatten([l, r]); | |
} | |
const termFor = bindingGroup => { | |
if(bindingGroup.length === 0) | |
return {}; | |
const head = R.head(bindingGroup); | |
const t = R.pipe( | |
R.toPairs, | |
R.map(p => { | |
return [ | |
R.slice(1, Infinity, Rx.first(p)), // remove '?' from SPARQL parameters | |
[ R.prop('value', Rx.second(p)) ] // TODO: add friendly type name back | |
]; | |
}), | |
R.fromPairs)(head); | |
return R.mergeWithKey(concatUnique, t, termFor(R.tail(bindingGroup))); | |
}; | |
const termsFrom = R.pipe( | |
R.groupBy(R.path(['?id', 'value'])), | |
R.values, | |
R.map(termFor)); | |
module.exports = { | |
termsFrom, | |
termFor | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment