Skip to content

fix: don't number introduced resources in repeatable groups - #658

Merged
tkuhn merged 1 commit into
masterfrom
fix/651-repeat-group-numbers
Aug 28, 2026
Merged

fix: don't number introduced resources in repeatable groups#658
tkuhn merged 1 commit into
masterfrom
fix/651-repeat-group-numbers

Conversation

@tkuhn

@tkuhn tkuhn commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Fixes #651.

Cause

IriItem auto-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 just template.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 __N suffix. this nanosuggestion is 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 requires hasNarrowScope(templateIri), evaluated inside the lazy label model rather than in the constructor. That matters: narrowScopeMap is filled statement by statement during TemplateContext.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 private transform(), needed to map the rendered IRI (artifact code expanded, __N suffixed) back to the template form the narrow-scope map is keyed on.

Test

New RepeatedLocalResourceLabelTest renders a repeatable statement item and reads the actual link labels:

  • introduced resource shared across statements → ["This nanosuggestion", "This nanosuggestion"]
  • local resource confined to the repeatable statement → ["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

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>
@tkuhn
tkuhn merged commit 35404b0 into master Aug 28, 2026
8 checks passed
@tkuhn
tkuhn deleted the fix/651-repeat-group-numbers branch August 28, 2026 07:45
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 5.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduced resources in repeat group show numbers

1 participant