Skip to content

fix: DatasetWrapper helpers yield distinct terms - #88

Draft
jeswr wants to merge 1 commit into
rdfjs:mainfrom
jeswr:fix/25-distinct-terms
Draft

fix: DatasetWrapper helpers yield distinct terms#88
jeswr wants to merge 1 commit into
rdfjs:mainfrom
jeswr:fix/25-distinct-terms

Conversation

@jeswr

@jeswr jeswr commented Jul 6, 2026

Copy link
Copy Markdown
Member

What this does

matchSubjectsOf and matchObjectsOf — and therefore subjectsOf, objectsOf and instancesOf, which delegate to them — now yield each term at most once, even when it occurs in multiple matching quads. Previously, data such as

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

made subjectsOf("p") yield <s> twice, though intuition implies distinct values.

How

Each generator tracks yielded terms in a Set<string> keyed on a value-derived string, so deduplication follows Term.equals semantics rather than object identity (RDF/JS terms compare by value, so the Set<Term> sketched in the issue would not catch equal-but-distinct instances). The key incorporates language, base direction and datatype for literals, and recurses through quoted-triple terms, so terms that differ only in those components are still yielded separately.

Tests

New cases in test/unit/dataset_wrapper.test.ts cover:

  • instancesOf yielding a subject once despite duplicate rdf:type paths (default graph + named graph)
  • subjectsOf / objectsOf yielding a term once across multiple matching quads
  • literals differing only in language tag not being collapsed
  • quoted-triple subjects deduplicating correctly

Closes #25

Supersedes: nothing — this concern is issue-only and not part of #61, #73 or #74.

Review timing: This draft was prepared with Claude; I (@jeswr) will personally review it before it progresses. I'm currently batching a lot of work in flight, so expect active review Wednesday-Friday (8-10 July).

matchSubjectsOf and matchObjectsOf (and therefore subjectsOf, objectsOf
and instancesOf) now yield each term at most once, even when it occurs
in multiple matching quads. Terms are deduplicated by a string key
derived from their value, following Term.equals semantics, so literals
that differ only in language, direction or datatype, and quoted-triple
terms, remain distinct.

Closes rdfjs#25

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dataset helpers should return distinct values

1 participant