fix: DatasetWrapper helpers yield distinct terms - #88
Draft
jeswr wants to merge 1 commit into
Draft
Conversation
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>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
matchSubjectsOfandmatchObjectsOf— and thereforesubjectsOf,objectsOfandinstancesOf, which delegate to them — now yield each term at most once, even when it occurs in multiple matching quads. Previously, data such asmade
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 followsTerm.equalssemantics rather than object identity (RDF/JS terms compare by value, so theSet<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.tscover:instancesOfyielding a subject once despite duplicaterdf:typepaths (default graph + named graph)subjectsOf/objectsOfyielding a term once across multiple matching quadsCloses #25
Supersedes: nothing — this concern is issue-only and not part of #61, #73 or #74.