clownface
clownface copied to clipboard
Add .distinct method to reduce result to unique terms/dataset/graph
After traversing a graph, many times there are duplicates. Sometimes this is wanted (e.g. counting matching pathes), so it can't be the default, but many times only the unique set is required.
A .distinct
method should be added that returns a new object with a reduced context with unique terms/dataset/graph.
From thomasz:
const map = graph
.toArray()
.reduce((distinct, node) => {
if (distinct.has(node.value) === false) {
distinct.set(node.value, node)
}
return distinct
}, new Map())
const distinct = [...map.values()]
This is just a workaround, because it returns an array of clownface with single context
The real deal should return a single object with distinct terms
/values
Here is a simple version of it that only checks the terms.
The implementation for clownface should by default check term
, dataset
and graph
of the context. It should be possible to pass arguments to check only specific parts. E.g.:
This would check only dataset
and graph
:
cf.distinct({ dataset: true, graph: true })