Shacl — linkml documentation

# Shacl

Warning

Beta implementation, some features may change

## Example Output

personinfo.shacl.ttl

## Overview

SHACL (Shapes Constraint Language) is a language for validating RDF graphs against a set of conditions

To run:

    gen-json-schema personinfo.yaml > personinfo.schema.json

## Docs

    NamedThing:
      slots:
        - id
        - name

    HasAliases:
      mixin: true
      attributes:
        aliases:
          multivalued: true

    Person:
      is_a: NamedThing
      mixins:
        - HasAliases
      slots:
        - birth_date
        - age_in_years
        - gender

..code-block:: turtle

> <https://w3id.org/linkml/tests/kitchen_sink/Person> a shacl:NodeShape ;

>   shacl:closed true ; shacl:ignoredProperties ( rdf:type ) ; shacl:property [ shacl:class <https://w3id.org/linkml/tests/kitchen_sink/BirthEvent> ;

>   > > shacl:maxCount 1 ; shacl:nodeKind shacl:BlankNode ; shacl:path <https://w3id.org/linkml/tests/kitchen_sink/has_birth_event> ],

>   > [ shacl:maxCount 1 ;

>   >   shacl:maxInclusive 999 ; shacl:minInclusive 0 ; shacl:path <https://w3id.org/linkml/tests/kitchen_sink/age_in_years> ],

>   > [ shacl:class <https://w3id.org/linkml/tests/kitchen_sink/FamilialRelationship> ;

>   >   shacl:nodeKind shacl:BlankNode ; shacl:path <https://w3id.org/linkml/tests/kitchen_sink/has_familial_relationships> ],

>   > [ shacl:maxCount 1 ;

>   >   shacl:path <https://w3id.org/linkml/tests/core/name> ; shacl:pattern “^\S+ \S+” ],

>   > [ shacl:class <https://w3id.org/linkml/tests/kitchen_sink/MedicalEvent> ;

>   >   shacl:nodeKind shacl:BlankNode ; shacl:path <https://w3id.org/linkml/tests/kitchen_sink/has_medical_history> ],

>   > [ shacl:class <https://w3id.org/linkml/tests/kitchen_sink/Address> ;

>   >   shacl:nodeKind shacl:BlankNode ; shacl:path <https://w3id.org/linkml/tests/kitchen_sink/addresses> ],

>   > [ shacl:maxCount 1 ;

>   >   shacl:path <https://w3id.org/linkml/tests/core/id> ],

>   > [ shacl:path <https://w3id.org/linkml/tests/kitchen_sink/aliases> ], [ shacl:class <https://w3id.org/linkml/tests/kitchen_sink/EmploymentEvent> ;

>   > > shacl:nodeKind shacl:BlankNode ; shacl:path <https://w3id.org/linkml/tests/kitchen_sink/has_employment_history> ] ;

>   shacl:targetClass <https://w3id.org/linkml/tests/kitchen_sink/Person> .

### Command Line

#### gen-shacl

Generate SHACL turtle from a LinkML model

    gen-shacl [OPTIONS] YAMLFILE

Options

-f, --format <format>

  Output format (default=ttl)

  Options

    ttl

--metadata, --no-metadata

  Include metadata in output (default=–metadata)

--useuris, --metauris

  Include metadata in output (default=–useuris)

-im, --importmap <importmap>

  Import mapping file

--log_level <log_level>

  Logging level (default=WARNING)

  Options

    CRITICAL | ERROR | WARNING | INFO | DEBUG

--mergeimports, --no-mergeimports

  Merge imports into source file (default=mergeimports)

Arguments

YAMLFILE

  Required argument

### Code

class linkml.generators.shaclgen.ShaclGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], format: str = 'ttl', genmeta: bool = False, gen_classvars: bool = True, gen_slots: bool = True, **kwargs)
  serialize(**args) → None

    Generate output in the required format

    Parameters

      kwargs – Generater specific parameters

    Returns

      Generated output