JSON-LD Contexts

Warning

The JSON-LD context generator does not yet include @embed directives necessary for conversion from RDF.

Warning

The JSON-LD context generator does not yet include @type directives except at the top level.

Overview

JSON-LD context provides mapping from JSON to RDF.

gen-jsonld-context personinfo.yaml > personinfo.context.jsonld

You can control the output via prefixes declarations and default_curi_maps.

Any JSON that conforms to the derived JSON Schema (see above) can be converted to RDF using this context.

Treatment of OBO prefixes

All OBO ontologies use prefixes that end in underscores (for example http://purl.obolibrary.org/obo/PATO_). Note that the JSON-LD 1.1 spec doesn’t allow trailing underscores on simple “flat” prefix maps, i.e this is not correct:

"@context": {
    "PATO": "http://purl.obolibrary.org/obo/PATO_",
     }

It must be represented as:

"@context": {
    "PATO": {
         "@id": "http://purl.obolibrary.org/obo/PATO_",
          "@prefix": true
     }

However, the former can still be convenient, so this can be done with a flag:

gen-jsonld-context --flatprefixes personinfo.yaml > personinfo.context.jsonld

However, this is not recommended and newer applications should switch to gen-prefix-map:

gen-prefix-map --flatprefixes personinfo.yaml > personinfo.prefixmap.json

Docs

Command Line

gen-jsonld-context

Generate jsonld @context definition from LinkML model

gen-jsonld-context [OPTIONS] YAMLFILE

Options

--base <base>

Base URI for model

--prefixes, --no-prefixes

Emit context for prefixes (default=–prefixes)

Default:

True

--model, --no-model

Emit context for model elements (default=–model)

Default:

True

--flatprefixes, --no-flatprefixes

Emit non-JSON-LD compliant prefixes as an object (deprecated: use gen-prefix-map instead).

Default:

False

-V, --version

Show the version and exit.

-f, --format <format>

Output format

Default:

'context'

Options:

context | json

--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.jsonldcontextgen.ContextGenerator(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, default_ns: str = None, context_body: dict = <factory>, slot_class_maps: dict = <factory>, emit_metadata: bool = False, model: Optional[bool] = True, base: Union[str, rdflib.namespace.Namespace, NoneType] = None, prefixes: Optional[bool] = True, flatprefixes: Optional[bool] = False)[source]
serialize(base: str | Namespace | None = None, **kwargs) str[source]

Generate output in the required format

Parameters:

kwargs – Generator specific parameters

Returns:

Generated output