feat: support RootNanopubPlaceholder in templates#453
Merged
Conversation
Renders as a read-only value that preserves the prior root on supersede/derive (via the existing ValueFiller sentinel path in ReadonlyItem.unifyWith) and defaults to the nanopub being published otherwise. Closes #452 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Templates declare the slot with a custom IRI typed as nt:RootNanopubPlaceholder (e.g. sub:rootNanopub a nt:RootNanopubPlaceholder), so the placeholder identity is the slot IRI, not the class IRI. Switch the ValueItem dispatch and TemplateContext.processValue resolution to template.isRootNanopubPlaceholder(iri), and seed the sentinel default in ReadonlyItem where the slot IRI is known. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
In PublishForm, the TemplateContexts for assertion/provenance/pubinfo are created without an existingNanopub, since the form is editable (isReadOnly = existingNanopub != null). But ReadonlyItem relied on context.getExistingNanopub() to resolve the local:nanopub sentinel to the filled-from nanopub's URI, so superseding a nanopub whose RootNanopubPlaceholder pointed at itself failed unification — the validator rejected the unresolved "local:nanopub" string. Add TemplateContext.fillSource (and getReferenceNanopub() which prefers existingNanopub and falls back to fillSource). PublishForm sets it from fillNp/improveNp before initStatements so ReadonlyItem's sentinel resolution, the RootNanopubPlaceholder default-seed skip, and the processValue resolution all see the actual nanopub. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
In supersede/derive mode, a ReadonlyItem resolves the local:nanopub sentinel to the fillSource's URI during unification — but the display label was then reading that URI back and calling it "this nanopublication", even though the fillSource is a *prior* nanopub, not the one being published. Tighten isNanopubValue/isAssertionValue to only treat matches against context.getExistingNanopub() as "this" (the nanopub being viewed). Fresh-publish's sentinel label is unaffected. Supersede/derive now falls through to the regular label/URI rendering so the prior nanopub's identity is visible. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
TemplateTest: verify isRootNanopubPlaceholder/isPlaceholder for a template that types a slot as nt:RootNanopubPlaceholder, and confirm unrelated slots are not matched. TemplateContextTest (new): cover the fillSource accessors and getReferenceNanopub fallback, and exercise processValue for the placeholder in the three resolution paths — fresh publish (sentinel -> targetNamespace), supersede with fillSource (sentinel -> existing np URI), explicit prior value preserved, and empty-model default. Co-Authored-By: Claude Opus 4.7 (1M context) <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.
Summary
nt:RootNanopubPlaceholder(shipped in nanopub-java 1.87.0, vocab PR Nanopublication/nanopub-java#67)ValueFillersentinel path inReadonlyItem.unifyWith), and defaults to the nanopub being published otherwiseReadonlyItemlabel now renders thelocal:nanopub/local:assertionsentinels as "this nanopublication"/"this assertion" (previously showed rawlocal:…strings)Closes #452
Test plan
mvn compilecleanmvn test— all 666 tests passRootNanopubPlaceholderand check fresh publish shows "this nanopublication"🤖 Generated with Claude Code