Skip to content

Comments

Add additional SHACL constraint support to the supermodel profile#255

Open
mgberg wants to merge 1 commit intoRDFLib:masterfrom
mgberg:mgg-more-shacl-constraints
Open

Add additional SHACL constraint support to the supermodel profile#255
mgberg wants to merge 1 commit intoRDFLib:masterfrom
mgberg:mgg-more-shacl-constraints

Conversation

@mgberg
Copy link

@mgberg mgberg commented Feb 11, 2026

Overview

This adds support for a variety of constraints on property values in the supermodel profile. This also populates these constraints based on SHACL shapes. Note that it would also be possible to source many of these fields from OWL, e.g. from datatype restrictions. Also note that this is not fully comprehensive SHACL support - there are a few other constraint components that are not included in this PR (e.g. qualified value shapes).

I'd be happy to make any changes to way these constraints are rendered based on any feedback from the community.

Example

Here is an example Turtle snippet (note that these constraints don't actually make sense but show how the various constraints will be displayed):

@prefix ex: <http://example.org/shacl-test#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

ex:TestOntology
    a owl:Ontology ;
    rdfs:label "Test Ontology" .

ex:TestClassShape
    a sh:NodeShape, owl:Class ;
    rdfs:label "Test Class";
    sh:targetClass ex:TestClass ;
    sh:property ex:DataPropertyShape ;
    sh:property ex:ObjectPropertyShape .

ex:DataPropertyShape
    a sh:PropertyShape ;
    sh:path ex:someDataProperty ;
    sh:datatype xsd:integer ;
    sh:nodeKind sh:Literal ;
    sh:minCount 0 ;
    sh:maxCount 5 ;
    sh:hasValue 42 ;
    sh:in ( 1 2 3 42 ) ;
    sh:pattern "^[0-9]+$" ;
    sh:languageIn ( "en" "es" ) ;
    sh:uniqueLang false ;
    sh:minLength 1 ;
    sh:maxLength 10 ;
    sh:minInclusive 0 ;
    sh:maxInclusive 100 ;
    sh:lessThan ex:hasObject ;
    sh:lessThanOrEquals ex:hasData ;
    sh:equals ex:hasData ;
    sh:disjoint ex:hasObject ;
    sh:description "A data property with a bunch of constraints." ;
    sh:name "Some Data Property" ;
    sh:defaultValue 0 .

ex:ObjectPropertyShape
    a sh:PropertyShape ;
    sh:path ex:someObjectProperty ;
    sh:class ex:RelatedClass ;
    sh:nodeKind sh:IRI ;
    sh:minCount 1 ;
    sh:maxCount 3 ;
    sh:hasValue ex:SpecificObject ;
    sh:in ( ex:RelatedClass ex:AnotherClass ex:SpecificObject ) ;
    sh:pattern "^http://example.org/.*" ;
    sh:languageIn ( "en" "fr" ) ;
    sh:uniqueLang true ;
    sh:minLength 5 ;
    sh:maxLength 100 ;
    sh:minExclusive 10 ;
    sh:maxExclusive 1000 ;
    sh:lessThan ex:hasData ;
    sh:lessThanOrEquals ex:hasObject ;
    sh:equals ex:hasObject ;
    sh:disjoint ex:hasData ;
    sh:order 1 ;
    sh:description "An object property with a bunch of constraints." ;
    sh:name "Some Object Property" ;
    sh:defaultValue ex:DefaultObject .

This turtle is rendered like this (as of when this PR was first opened):
image

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.

1 participant