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-shacl personinfo.yaml > personinfo.shacl.ttl

Docs

Example Input:

NamedThing:
  slots:
    - id
    - name

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

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

Example Output:

<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

True

--useuris, --metauris

Include metadata in output

Default

True

-im, --importmap <importmap>

Import mapping file

--log_level <log_level>

Logging level

Default

WARNING

Options

CRITICAL | ERROR | WARNING | INFO | DEBUG

-v, --verbose

verbosity

--mergeimports, --no-mergeimports

Merge imports into source file (default=mergeimports)

Arguments

YAMLFILE

Required argument

Code

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

Generate output in the required format

Parameters

kwargs – Generater specific parameters

Returns

Generated output