fix: don't number introduced resources in repeatable groups - #658
Merged
Conversation
A local resource rendered inside a repeatable statement group got its label
auto-numbered ("This nanosuggestion 1", "… 2"), even when the resource is the
same in every repetition. That is the case for the template's introduced
resource, which a repeatable statement typically just refers to (issue #651).
Only the form labels were affected; the published nanopubs were correct.
Numbering now additionally requires the resource to be narrowly scoped to the
statement, which is exactly the condition under which
StatementItem.RepetitionGroup#transform appends the "__N" suffix and thus mints
a fresh instance per repetition.
The check is done lazily inside the link label model rather than in the IriItem
constructor: TemplateContext's narrow-scope map is filled statement by statement
during initStatements(), so at construction time of the first repetition group
it is still incomplete and the answer would depend on statement order.
Adds Template.getTemplateIri(), exposing the existing private transform() that
maps a rendered IRI (artifact code expanded, "__N" suffixed) back to the
template form the narrow-scope map is keyed on.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
|
🎉 This PR is included in version 5.13.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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.
Fixes #651.
Cause
IriItemauto-numbers repeated local resources (added in 04c8c7c so that e.g. "a context-specific alias 1 / 2" stay distinguishable inside a repeatable group). The condition was justtemplate.isLocalResource(iri), which is too broad.Only resources that are narrowly scoped to a single statement actually get a fresh instance per repetition — that is exactly the condition in
StatementItem.RepetitionGroup#transform(getRepeatIndex() > 0 && context.hasNarrowScope(iri)) that appends the__Nsuffix.this nanosuggestionis the introduced resource used as subject in many statements, so it is not narrow-scoped and denotes the same thing in every repetition. Hence the published nanopubs were fine and only the label was wrong.Fix
IriItem: numbering now also requireshasNarrowScope(templateIri), evaluated inside the lazy label model rather than in the constructor. That matters:narrowScopeMapis filled statement by statement duringTemplateContext.initStatements(), so at construction time of the first repetition group it is still incomplete and the answer would depend on statement order. At render time it is complete.Template.getTemplateIri(IRI): new public accessor exposing the existing privatetransform(), needed to map the rendered IRI (artifact code expanded,__Nsuffixed) back to the template form the narrow-scope map is keyed on.Test
New
RepeatedLocalResourceLabelTestrenders a repeatable statement item and reads the actual link labels:["This nanosuggestion", "This nanosuggestion"]["A context-specific alias 1", "A context-specific alias 2"](regression guard for 04c8c7c)The first test fails on the pre-fix code with exactly the symptom from the issue (
This nanosuggestion 1,This nanosuggestion 2). Full suite: 1215 tests, 0 failures.🤖 Generated with Claude Code