clownface icon indicating copy to clipboard operation
clownface copied to clipboard

Add .distinct method to reduce result to unique terms/dataset/graph

Open bergos opened this issue 5 years ago • 3 comments

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.

bergos avatar Dec 13 '19 16:12 bergos

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()]

l00mi avatar Apr 20 '20 09:04 l00mi

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

tpluscode avatar Apr 20 '20 09:04 tpluscode

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 })

bergos avatar Oct 16 '20 13:10 bergos