Python API reference
The supported library interface consists of two decoding functions and one graph-writing utility. The signatures, defaults, parameter descriptions, and raised exceptions below are rendered from the live public functions and their docstrings. See Python library guide for task-oriented guidance.
- json2graph.library.decode_json_project(json_file_path, base_uri=None, language='', correct=False, invalid_stereotype_policy='preserve', invalid_cardinality_policy='preserve', unresolved_model_element_policy='omit', transformation_metadata='none', append_content_hash=False, path_order_policy='warn', property_assignment_policy='warn')
Decode an OntoUML JSON project, including supported diagrammatic data.
The returned RDFLib graph contains the project, domain-level model, and supported diagrammatic resources. The decoder expects the OntoUML JSON structure but does not perform JSON Schema validation.
- Parameters:
json_file_path (str) – Path to the OntoUML JSON file.
base_uri (str or None) – Explicit absolute base URI for generated resources. When omitted, a deterministic
urn:uuid:base is derived from the parsed JSON document.language (str) – Language tag applied to source
nameliterals. An empty string leaves names without a language tag.correct (bool) – Enable the legacy class and property correction pass. This is independent of the explicit policy parameters.
invalid_stereotype_policy (str) – Handle stereotypes invalid for their element type with
preserve,omit, orerror. Default ispreserve.invalid_cardinality_policy (str) – Handle invalid cardinalities with
preserve, limited saferepair, orerror. Default ispreserve.unresolved_model_element_policy (str) – Handle unresolved diagrammatic
modelElementreferences withpreserve,omit, orerror. Default isomit.transformation_metadata (str) – Return no provenance with
noneor add it to the graph withembedded. Sidecar output is not available through the library.append_content_hash (bool) – Append the deterministic content UUID below a supplied
base_uri.path_order_policy (str) – Handle path-point order with
warnor add a non-normativerdfs:commentwithcomment. Default iswarn.property_assignment_policy (str) – Handle non-empty
propertyAssignmentswithwarnor preserve canonical JSON in a non-normative comment withcomment. Default iswarn.
- Returns:
Decoded RDF graph.
- Return type:
Graph
- Raises:
ValueError – If an option is invalid or an
errorpolicy rejects source content.OSError – If the input file cannot be read.
- json2graph.library.decode_json_model(json_file_path, base_uri=None, language='', correct=False, invalid_stereotype_policy='preserve', invalid_cardinality_policy='preserve', unresolved_model_element_policy='omit', transformation_metadata='none', append_content_hash=False, path_order_policy='warn', property_assignment_policy='warn')
Decode the domain-level model from an OntoUML JSON project.
The returned RDFLib graph excludes project and diagrammatic resources while retaining model elements, including enumeration literals. The decoder expects the OntoUML JSON structure but does not perform JSON Schema validation.
- Parameters:
json_file_path (str) – Path to the OntoUML JSON file.
base_uri (str or None) – Explicit absolute base URI for generated resources. When omitted, a deterministic
urn:uuid:base is derived from the parsed JSON document.language (str) – Language tag applied to source
nameliterals. An empty string leaves names without a language tag.correct (bool) – Enable the legacy class and property correction pass. This is independent of the explicit policy parameters.
invalid_stereotype_policy (str) – Handle stereotypes invalid for their element type with
preserve,omit, orerror. Default ispreserve.invalid_cardinality_policy (str) – Handle invalid cardinalities with
preserve, limited saferepair, orerror. Default ispreserve.unresolved_model_element_policy (str) – Handle unresolved diagrammatic
modelElementreferences withpreserve,omit, orerror. Default isomit.transformation_metadata (str) – Return no provenance with
noneor add it to the graph withembedded. Sidecar output is not available through the library.append_content_hash (bool) – Append the deterministic content UUID below a supplied
base_uri.path_order_policy (str) – Accepted for parity with project decoding. Model-only output contains no paths, so this option does not change the graph.
property_assignment_policy (str) – Handle non-empty
propertyAssignmentson retained model elements withwarnorcomment. Default iswarn.
- Returns:
Decoded model-only RDF graph.
- Return type:
Graph
- Raises:
ValueError – If an option is invalid or an
errorpolicy rejects source content.OSError – If the input file cannot be read.
- json2graph.library.save_graph_file(ontouml_graph, output_file_path, syntax)
Serialize an RDFLib graph to the requested file.
Accepted syntax names are
turtle,ttl,turtle2,xml,pretty-xml,json-ld,ntriples,nt,nt11,n3,trig,trix, andnquads.- Parameters:
ontouml_graph (Graph) – Graph to serialize.
output_file_path (str) – Complete destination path, including filename and extension.
syntax (str) – Supported RDFLib serialization name.
- Raises:
ValueError – If
syntaxis not supported.OSError – If the output file cannot be written.
- Return type:
None