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.
You can also combine a JSON instance file with a JSON-LD context using simple code or a tool like jq:
jq -s '.[0] * .[1]' examples/organization-data.json examples/organization.context.jsonld > examples/organization-data.jsonld
The above generated JSON-LD file can be converted to other RDF serialization formats such as N-Triples. For example we can use Apache Jena as follows:
riot examples/organization-data.jsonld > examples/organization-data.nt
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-parsable prefixes as an object
- Default
False
- -f, --format <format>
Output format (default=context)
- Options
context | json
- --metadata, --no-metadata
Include metadata in output (default=–metadata)
- --useuris, --metauris
Include metadata in output (default=–useuris)
- -im, --importmap <importmap>
Import mapping file
- --log_level <log_level>
Logging level (default=WARNING)
- Options
CRITICAL | ERROR | WARNING | INFO | DEBUG
- --mergeimports, --no-mergeimports
Merge imports into source file (default=mergeimports)
Arguments
- YAMLFILE
Required argument
Code
- class linkml.generators.jsonldcontextgen.ContextGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], **kwargs)[source]
- serialize(**kwargs) str
Generate output in the required format
- Parameters
kwargs – Generater specific parameters
- Returns
Generated output