write_jsonld_context
- write_jsonld_context(converter: Converter, path: str | Path, *, include_synonyms: bool = False, expand: bool = False) None [source]
Write the converter’s bijective map as a JSON-LD context to a file.
- Parameters:
converter – The converter to export
path – The path to a file to write to
include_synonyms – If true, includes CURIE prefix synonyms. URI prefix synonyms are not output.
expand – If False, output a dictionary-like
@context
element. If True, use@prefix
and@id
as keys for the CURIE prefix and URI prefix, respectively, to maximize compatibility.
The following example shows writing a JSON-LD context:
import curies converter = curies.load_prefix_map( { "CHEBI": "http://purl.obolibrary.org/obo/CHEBI_", } ) curies.write_jsonld_context(converter, "example_context.json")
{ "@context": { "CHEBI": "http://purl.obolibrary.org/obo/CHEBI_" } }
Because some implementations of JSON-LD do not like URI prefixes that end with an underscore
_
, we can use theexpand
keyword to turn on more verbose JSON-LD context output that contains explicit@prefix
and@id
annotationsimport curies converter = curies.load_prefix_map( { "CHEBI": "http://purl.obolibrary.org/obo/CHEBI_", } ) curies.write_jsonld_context(converter, "example_context.json", expand=True)
{ "@context": { "CHEBI": { "@id": "http://purl.obolibrary.org/obo/CHEBI_", "@prefix": true } } }