ShEx

Example Output

personinfo.shex

Overview

ShEx, short for Shape Expressions Language is a modeling language for RDF files. This generator can be used to create ShEx shapefiles, which can then be used to validate RDF data.

ShEx provides similar functionality to SHACL, which has its own validator

To run:

gen-shex personinfo.yaml > personinfo.shex

Translation

An example of translating the personinfo schema is shown below.

<NamedThing>  (
    CLOSED {
       (  $<NamedThing_tes> (  schema:name @linkml:String ? ;
             schema:description @linkml:String ? ;
             schema:image @linkml:String ?
          ) ;
          rdf:type [ <NamedThing> ]
       )
    } OR @<Concept> OR @<Organization> OR @<Person>
)
<Person> CLOSED {
    (  $<Person_tes> (  &<NamedThing_tes> ;
          rdf:type [ <NamedThing> ] ? ;
          &<HasAliases_tes> ;
          rdf:type [ <HasAliases> ] ? ;
          <primary_email> @linkml:String ? ;
          schema:birthDate @linkml:String ? ;
          <age_in_years> @linkml:Integer ? ;
          schema:gender @<GenderType> ? ;
          <current_address> @<Address> ? ;
          <has_employment_history> @<EmploymentEvent> * ;
          <has_familial_relationships> @<FamilialRelationship> * ;
          <has_medical_history> @<MedicalEvent> * ;
          <aliases> @linkml:String *
       ) ;
       rdf:type [ schema:Person ]
    )
}

Docs

Command Line

gen-shex

Generate a ShEx Schema for a LinkML model

gen-shex [OPTIONS] YAMLFILE

Options

-o, --output <output>

Output file name

-V, --version

Show the version and exit.

-f, --format <format>

Output format

Default:

'shex'

Options:

shex | json | rdf

--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.shexgen.ShExGenerator(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, collections.abc.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, shex: ShExJSG.SchemaWithContext.Schema = <factory>, shapes: list = <factory>, shape: Optional[ShExJSG.ShExJ.Shape] = None, list_shapes: list[ShExJSG.ShExJ.IRIREF] = <factory>)[source]
serialize(**kwargs) str

Generate output in the required format

Parameters:

kwargs – Generator specific parameters

Returns:

Generated output