feat(gen-shacl): add --message-template for sh:message on property shapes#10
Open
jdsika wants to merge 1 commit into
Open
feat(gen-shacl): add --message-template for sh:message on property shapes#10jdsika wants to merge 1 commit into
jdsika wants to merge 1 commit into
Conversation
ab3a0ff to
0f541b2
Compare
c3751dd to
06ac9fc
Compare
0f541b2 to
39e9d7d
Compare
06ac9fc to
97b9619
Compare
39e9d7d to
134bae4
Compare
97b9619 to
f54897c
Compare
1243622 to
970f089
Compare
603bc8d to
de4a8a3
Compare
0cd5ed1 to
af4b68d
Compare
f54897c to
b7d699f
Compare
…apes
Add a new --message-template option that attaches sh:message literals to
each property shape using a user-defined template string.
Supported placeholders:
{name} — slot name (underscore-separated)
{title} — slot title (human-readable), falls back to name
{description} — slot description, falls back to empty string
{comments} — slot comments joined with "; ", falls back to empty string
{class} — enclosing class name
{path} — property IRI (compact or full)
The resulting message is stripped of leading/trailing whitespace and
omitted entirely when empty (avoids blank sh:message literals).
When --default-language is also set, the literal is language-tagged.
Example:
gen-shacl --message-template "{name} ({class}): {description} [{comments}]"
Signed-off-by: Carlo van Driesten <carlo.van-driesten@bmw.de>
af4b68d to
4858381
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