SHACL#
Warning
Beta implementation, some features may change
Example Output#
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
- --closed, --non-closed#
Use ‘–closed’ to generate closed SHACL shapes. Use ‘–non-closed’ to generate open SHACL shapes.
- Default:
True
- -s, --suffix <suffix>#
Use –suffix to append given string to SHACL class name (e. g. –suffix Shape: Person becomes PersonShape).
- --include-annotations, --exclude-annotations#
Use –include-annotations to include annotations of slots, types, and classes in the generated SHACL shapes.
- Default:
False
- -V, --version#
Show the version and exit.
- -f, --format <format>#
Output format
- Default:
'ttl'
- Options:
ttl
- --metadata, --no-metadata#
Include metadata in output
- Default:
True
- --useuris, --metauris#
Use class and slot URIs over model uris
- 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. Takes precedence over –log_level.
- --mergeimports, --no-mergeimports#
Merge imports into source file (default=mergeimports)
- --stacktrace, --no-stacktrace#
Print a stack trace when an error occurs
- Default:
False
Arguments
- YAMLFILE#
Required argument
Code#
- class linkml.generators.shaclgen.ShaclGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition, ForwardRef('Generator'), pathlib.Path], schemaview: Optional[linkml_runtime.utils.schemaview.SchemaView] = None, format: Optional[str] = None, metadata: bool = True, useuris: Optional[bool] = None, log_level: Optional[int] = 30, mergeimports: Optional[bool] = True, source_file_date: Optional[str] = None, source_file_size: Optional[int] = None, logger: Optional[logging.Logger] = None, verbose: Optional[bool] = None, output: Optional[str] = None, namespaces: Optional[linkml_runtime.utils.namespaces.Namespaces] = None, directory_output: bool = False, base_dir: str = None, metamodel_name_map: Dict[str, str] = None, importmap: Union[str, Mapping[str, str], NoneType] = None, emit_prefixes: Set[str] = <factory>, metamodel: linkml.utils.schemaloader.SchemaLoader = None, stacktrace: bool = False, include: Union[str, pathlib.Path, linkml_runtime.linkml_model.meta.SchemaDefinition, NoneType] = None, closed: bool = True, suffix: str = None, include_annotations: bool = False, **_kwargs)[source]#