Skip to content

Dataset helpers should return distinct values #25

@langsamu

Description

@langsamu

At the moment DatasetWrapper.subjectsOf (and the other mwthods here) might return the same term multiple times in its result Iterable, though intuition would imply distinct values.

Consider this input:

<s> <p> <o1> .
<s> <p> <o2> .

subjectsOf("p") translates (conceptually) to the following:

for (const quad of dataset.match(undefined, p, undefined, undefined)) {
  yield quad.subject
}

which matches both statements in the input, so it returns <s> twice.


Instead we should ensure that only unique terms are returned:

const seen = new Set<Term>
for (const quad of dataset.match(undefined, p, undefined, undefined)) {
  if (seen.has(quad.subject) continue
  seen.add(quad.subject)
  yield quad.subject
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions