feat(gen-shacl): add --message-template for sh:message on property shapes#10
Open
jdsika wants to merge 1 commit intofeat/generators-default-languagefrom
Open
feat(gen-shacl): add --message-template for sh:message on property shapes#10jdsika wants to merge 1 commit intofeat/generators-default-languagefrom
jdsika wants to merge 1 commit intofeat/generators-default-languagefrom
Conversation
ab3a0ff to
0f541b2
Compare
0f263f0 to
c3751dd
Compare
…apes
Add a --message-template CLI option to gen-shacl that generates
sh:message literals on every property shape from a user-supplied
template string.
Supported placeholders:
- {name} - slot name (underscore-separated LinkML identifier)
- {title} - slot title (human-readable), falls back to name
- {class} - enclosing class name
- {path} - property IRI
Example usage:
gen-shacl --message-template 'Validation of {name} failed!' schema.yaml
This enables SHACL validators (e.g. pyshacl) to produce human-friendly
error messages identifying the specific constraint that was violated.
Changes:
- New message_template field on ShaclGenerator dataclass
- Template expansion after sh:name / sh:description emission
- Uses prop_pv_text for language tag support when combined with
--default-language (sh:message gets language tag per SHACL 2.1.5)
- Invalid/positional placeholders and format specs raise ValueError
with helpful message (catches KeyError, IndexError, ValueError)
- Empty and whitespace-only templates normalised to None (no emission)
- New --message-template Click CLI option
- 10 new tests: basic, title/class placeholders, backward-compat,
invalid/positional/format-spec errors, empty/whitespace, combined
Signed-off-by: Carlo van Driesten <carlo.van-driesten@bmw.de>
c3751dd to
06ac9fc
Compare
0f541b2 to
39e9d7d
Compare
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
Adds a
--message-templateCLI option togen-shaclthat generatessh:messageliterals on every SHACL property shape from a user-supplied template string. This enables SHACL validators (e.g. pyshacl) to produce human-friendly error messages identifying the specific constraint that was violated.Depends on: #9 (
--default-languageflag)Problem
LinkML's SHACL generator currently produces property shapes without
sh:message. When SHACL validation fails, the error report contains only technical details (focus node, result path, constraint component) but no human-readable explanation. Users must manually trace the violation back to the source shape.The SHACL specification (§2.1.5) explicitly supports
sh:messagefor this purpose:Usage
Supported placeholders
{name}has_speed{title}Has Speed{class}Vehicle{path}http://example.org/hasSpeedChanges
gen-shacl (
shaclgen.py)message_templatefield with__post_init__whitespace normalisationsh:name/sh:descriptionemissionprop_pv_textfor language tag support when combined with--default-language(sh:messagegets language tag per SHACL §2.1.5)ValueErrorwith helpful message (catchesKeyError,IndexError,ValueError)None(nosh:messageemitted)--message-templateClick CLI optionTests (10 new)
{name},{title},{class},{path}sh:message)ValueError{0}raisesValueError{name:d}raisesValueError--default-language(sh:messagegets@entag)Backward compatibility
None— existing behaviour is completely unchangedNoneStandards compliance
sh:messageacceptsxsd:stringorrdf:langStringsh:messageis non-validating metadata for error reports@langtag onsh:resultMessagein reportsTesting