Codegen (experimental)

triplemodel-codegen generates stub TripleModel classes from OWL/RDFS ontologies.

Limitations

  • Only owl:DatatypeProperty and owl:ObjectProperty are emitted (plain rdf:Property is ignored).

  • All properties are typed as str; rdfs:range is not read.

  • Every class gets id_field = "slug" and a slug: str field.

  • Duplicate local field names (different predicate IRIs) keep the first property only (a UserWarning is emitted).

  • Multiple rdfs:subClassOf parents: last parent wins in the emitted hierarchy.

Missing ontology files raise FileNotFoundError when the path has a known suffix (.ttl, .owl, etc.).

Experimental OWL/RDFS → TripleModel stub codegen.

triplemodel.codegen.generate_models_from_graph(graph)[source]

Return Python source for stub TripleModel subclasses.

Return type:

str

Parameters:

graph (RdfGraph)

triplemodel.codegen.ontology_graph(source, *, format=None)[source]

Load an ontology file into a graph.

Return type:

RdfGraph

Parameters:

CLI entry point for OWL/RDFS stub codegen.

triplemodel.codegen.cli.main(argv=None)[source]
Return type:

int

Parameters:

argv (list[str] | None)