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: ~typing.Union[str, ~typing.TextIO, ~linkml_runtime.linkml_model.meta.SchemaDefinition, ~linkml.utils.generator.Generator], schemaview: ~typing.Optional[~linkml_runtime.utils.schemaview.SchemaView] = None, format: ~typing.Optional[str] = None, metadata: bool = <factory>, useuris: ~typing.Optional[bool] = None, log_level: int = 30, mergeimports: ~typing.Optional[bool] = <factory>, source_file_date: ~typing.Optional[str] = None, source_file_size: ~typing.Optional[int] = None, logger: ~typing.Optional[~logging.Logger] = None, verbose: ~typing.Optional[bool] = None, output: ~typing.Optional[str] = None, namespaces: ~typing.Optional[~linkml_runtime.utils.namespaces.Namespaces] = None, directory_output: bool = False, base_dir: ~typing.Optional[str] = None, metamodel_name_map: ~typing.Optional[~typing.Dict[str, str]] = None, importmap: ~typing.Optional[~typing.Union[str, ~typing.Mapping[str, str]]] = None, emit_prefixes: ~typing.Set[str] = <factory>, metamodel: ~typing.Optional[~linkml.utils.schemaloader.SchemaLoader] = None, **_kwargs)[source]
serialize(**args) None[source]

Generate output in the required format

Parameters

kwargs – Generater specific parameters

Returns

Generated output