Skip to content

SHACL shape templates and property shape docs, preferred language, valid prefixed names - #38

Merged
ajuvercr merged 3 commits into
mainfrom
claude/dreamy-mendel-uxxfa0
Nov 17, 2026
Merged

ajuvercr merged 3 commits into
mainfrom
claude/dreamy-mendel-uxxfa0

Conversation

@ajuvercr

Copy link
Copy Markdown
Collaborator

SHACL shape templates in completion

At a predicate position, two snippet completions are built from the SHACL shapes that apply to the subject:

  • shape template: required properties: every property with sh:minCount >= 1.
  • shape template: all properties: every property the shapes declare.

Properties the subject already has are left out.

  • Which shapes apply:
    • sh:targetClass, including superclasses from the ontologies and implicit class targets;
    • sh:targetSubjectsOf;
    • sh:targetObjectsOf, so blank nodes such as RML predicate-object maps get templates;
    • sh:targetNode.
  • Included shapes: a shape's properties include those of the shapes and property shapes it lists in sh:node / sh:and. Branches of sh:or / sh:xone are alternatives, so none of them is assumed.
  • Placeholders:
    • sh:hasValue is filled in, and sh:in becomes a choice.
    • sh:alternativePath becomes a choice of predicates and counts as satisfied by any one of them.
    • Nested values expand to [ … ] with their required properties, up to two levels deep. They come from sh:node, the first sh:or branch with a node shape, shapes targeting the objects of the predicate, or shapes for its sh:class.
    • sh:nodeKind / sh:datatype choose between <…>, "…", typed literals and plain placeholders.
  • Insertion: the template goes in at the cursor without eating a following . or ], replaces a partially typed predicate, and continuation lines follow the indentation.
  • Config: can be disabled with completion_shape_template.

SHACL property shapes on predicates

Hover on a predicate shows every property shape that applies to it for this subject:

  • sh:name and sh:description, and also the property shape's rdfs:label and rdfs:comment (unless they repeat the SHACL text);
  • the alternatives of an sh:alternativePath;
  • a constraint summary: cardinality, node kind, datatype, class, sh:in, sh:hasValue, sh:node and sh:or / sh:xone shapes, pattern, lengths and ranges, languages, and a non-default severity.

Property completions get the same documentation. Predicates that only the shapes declare are offered too, marked "required by shape" where a shape requires them. The hover can be disabled with hover_shape_property.

Templates, hover and completion share one shape model (shapes::model), so they agree on which shapes apply.

One language for displayed text

Wherever text is shown, one language is chosen: untagged text, then English (en, en-*), then the first language (util::lang_text). This applies to:

  • ontology class and property titles and descriptions (previously every language, in random order);
  • SHACL validation messages (sh:message, else rdfs:comment);
  • shape template placeholders;
  • the new shape documentation.

Fixes found on the way:

  • MyTerm's sophia Term impl reported no datatype or language for literals, so every literal entered the store as a plain string. It now reports xsd:string, rdf:langString or the literal's datatype, and its language tag.
  • The conversions to oxigraph checked the datatype before the language, which would turn a language-tagged literal into an rdf:langString typed literal without a language.

Valid prefixed names

Prefixes::shorten stripped the first matching namespace and wrote whatever remained. With @prefix rml: <http://w3id.org/rml/>, the IRI http://w3id.org/rml/shapes/X became rml:shapes/X, which is not a valid prefixed name in Turtle, TriG, N3 or SPARQL. Completion inserted it as is.

  • Prefixes::shorten only returns names whose local part is a valid PN_LOCAL; otherwise the IRI is written in full. When several prefixes match, the longest namespace wins.
  • Prefixes::shorten_compact keeps the permissive form for JSON-LD compact IRIs (css:dist/Server#port).
  • LangHelper::shorten / write_iri let completion write IRIs per language. Class and property completion used to insert an IRI that could not be shortened as a bare http://…, which is invalid Turtle. It is now <…> in Turtle-family languages, and a plain string in JSON-LD.

Testing

  • New e2e tests:
    • shape_templates.rs (11);
    • shape_docs.rs (7);
    • prefixed_names.rs (4, each failing on the previous code).
  • Unit tests for language selection, PN_LOCAL validation, longest-prefix selection and snippet helpers.
  • cargo test --workspace passes (561 tests).
  • Also ran the real binary over stdio with the RML shapes from support the configuration of multiple ontologies and shapes about the same namespace #30:
    • rml:TriplesMap gets rml:logicalSource plus a choice of rml:subjectMap / rml:subject / rml:quotedTriplesMap;
    • predicate-object map blank nodes get their predicate and object choices;
    • hover on rml:subjectMap shows the ontology docs followed by both property shapes and their constraints.

Note: the RML shapes declare rml:template / rml:constant / rml:reference with sh:maxCount 1 but no sh:minCount. That is why neither the templates nor validation treat them as required (the second symptom in #30).


Generated by Claude Code

At a predicate position, offer two snippet completions built from the
SHACL shapes that apply to the subject:

- "shape template: required properties": every property with
  `sh:minCount >= 1`,
- "shape template: all properties": every property the shapes declare.

Properties the subject already has are left out.

Shapes apply through `sh:targetClass` (including superclasses from the
ontologies, and implicit class targets), `sh:targetSubjectsOf`,
`sh:targetObjectsOf` (so blank nodes such as RML predicate-object maps get
templates) and `sh:targetNode`. A shape's properties include those of the
shapes and property shapes it lists in `sh:node` / `sh:and`.

Values are snippet placeholders shaped by the constraints:
- `sh:hasValue` is filled in, and `sh:in` becomes a choice.
- `sh:alternativePath` becomes a choice of predicates. Optional
  declarations it covers are folded into it, and it is satisfied by any
  one of its paths.
- A nested value (`sh:node`, the first `sh:or` / `sh:xone` branch with a
  node shape, shapes targeting the objects of the predicate, or shapes
  for its `sh:class`) expands to `[ … ]` with its required properties,
  up to two levels deep.
- `sh:nodeKind` / `sh:datatype` choose between `<…>`, `"…"`, typed
  literals and plain placeholders.

The template is inserted at the cursor without eating a following `.` or
`]`, replaces a partially typed predicate, and continuation lines follow
the indentation. Templates are offered for Turtle-family languages with
shape validation (`LangHelper::shape_templates`) and can be disabled with
`completion_shape_template`.
…uage

Hover on a predicate now also shows every SHACL property shape that
applies to it for this subject:

- `sh:name` and `sh:description`, and also the property shape's
  `rdfs:label` and `rdfs:comment` (unless they repeat the SHACL text),
- the alternatives of an `sh:alternativePath`,
- a constraint summary: cardinality, node kind, datatype, class, `sh:in`,
  `sh:hasValue`, `sh:node` and `sh:or` / `sh:xone` shapes, pattern,
  lengths and ranges, languages, and a non-default severity.

Shapes apply by the same targets as the shape templates. That code moved
to `shapes::model`, so hover, completion and templates agree. Property
completions get the same documentation, and predicates only the shapes
declare are offered too, marked when a shape requires them. IRIs in this
documentation fall back to the shape documents' prefixes and are only
shortened to valid prefixed names. The hover can be disabled with
`hover_shape_property`.

Wherever text is shown, one language is chosen: untagged text, then
English (`en`, `en-*`), then the first language (`util::lang_text`).
This now applies to ontology class and property titles and
descriptions (previously every language, in random order), SHACL
validation messages (`sh:message`, else `rdfs:comment`), shape template
placeholders and the new shape documentation.

Fixes found on the way:
- `MyTerm`'s sophia `Term` impl reported no datatype or language for
  literals, so every literal entered the store as a plain string. It now
  reports `xsd:string`, `rdf:langString` or the literal's datatype, and
  its language tag.
- The conversions to oxigraph checked the datatype before the language,
  which would turn a language-tagged literal into an `rdf:langString`
  typed literal without a language.
- Removed imports `open_imports` left behind in `lov::fetch`.
`Prefixes::shorten` stripped the first matching namespace and wrote
whatever remained, so with `@prefix rml: <http://w3id.org/rml/>` the IRI
`http://w3id.org/rml/shapes/X` became `rml:shapes/X`. That is not a valid
prefixed name in Turtle, TriG, N3 or SPARQL, and completion inserted it as
is.

- `Prefixes::shorten` only returns names whose local part is a valid
  `PN_LOCAL` (`is_local_name`); otherwise the IRI is written in full.
  When several prefixes match, the longest namespace wins, so a declared
  `rmlsh: <http://w3id.org/rml/shapes/>` gives `rmlsh:X`.
- `Prefixes::shorten_compact` keeps the permissive form for JSON-LD,
  whose compact IRIs accept any suffix (`css:dist/Server#port`), also
  preferring the longest prefix.
- `LangHelper::shorten` / `LangHelper::write_iri` let completion write an
  IRI the way the language needs it. Class and property completion used to
  insert an IRI that could not be shortened as a bare `http://…`, which is
  invalid Turtle. It is now `<…>` in Turtle-family languages, and a plain
  string in JSON-LD.
- Shape documentation drops its own workaround and uses `shorten`, falling
  back to the shape documents' prefixes as before.
@ajuvercr
ajuvercr merged commit 250fb5e into main Nov 17, 2026
2 checks passed
@ajuvercr
ajuvercr deleted the claude/dreamy-mendel-uxxfa0 branch November 17, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants