Skip to content

SHACL

Generate SHACL shapes, serialized as N-Triples or Turtle.

Terminal window
ohi get w3c/prov-o
ohi linkml to shacl --open --to prov-o.shacl.ttl prov-o.linkml.yaml
Try it in the playground, with PROV-O
formatRdfFormatdefault ttl
CLI --format

The RDF serialization of the output.

  • ttl Turtle, with prefixes and pretty-printed.
  • nt N-Triples, one statement per line.
only_classes_from_root_schemabooleandefault false
CLI --only-classes-from-root-schemaScala onlyClassesFromRootSchema

Whether to include only the classes and enums of the root schema. This is useful for one output file per schema file, without the imported classes in each.

openbooleandefault false
CLI --open

Whether every shape is open, allowing properties beyond the ones in the schema. Shapes of classes whose extra_slots allows them are open anyway.

The SHACL generator gives a slot whose range is a class an sh:class constraint with that class. SHACL checks sh:class and sh:targetClass with the rdfs:subClassOf triples in the data graph. So for a value typed with a subclass to conform, add the class hierarchy to the data graph, for example the output of the RDFS generator:

Terminal window
pyshacl -s shapes.ttl -e schema-rdfs.ttl data.ttl

Subclasses from other schemas are accepted this way too.

In RDF, rdf:type holds the type designator, so the SHACL generator emits no property shape for the designator slot. A slot whose range has a type designator gets sh:class with that class, like any other class range.

With the class hierarchy in the data graph, the shape of a class also checks the instances of its subclasses, which can have more slots. So the shape of a class with subclasses is open (sh:closed false).

A subclass can’t accept data that the shape of its parent class or mixin rejects. For example, if a subclass makes a slot multivalued, its instances with more than one value fail the shape of the parent, where the slot is single-valued.