Compiler and extension reference#
plumb gen compiles an ontology and its SHACL shapes into a deterministic
Python package. For a step-by-step walk-through, see
Write and compile a domain package.
Command line#
# compile a local ontology file
plumb gen --file pumps.ttl --name Pumps --out pumps
# fetch by IRI: ontoenv resolves and merges the owl:imports closure
plumb gen --iri https://example.org/ontology/pumps --name Pumps --out pumps
# merge extra graphs, such as shapes published separately
plumb gen --file core.ttl --extra shapes.ttl --name Pumps --out pumps
--source records provenance metadata; --no-overlay skips built-in UX
overlays.
Each generated package directory contains:
__init__.py— generated classes, property schemas, andREGISTRY,enums.py— enumeration constants (when the ontology defines an enum root),_shapes.ttl— exact input shapes graph (loaded lazily byvalidate()andexport_ontology()),_symbols.json— dependency metadata for linking extensions without importing base Python code,_support.json— per-constraint enforcement and binding diagnostics, and_generated.json— file ownership manifest used to clean stale files on regeneration.
Reviewing upgrades with plumb diff#
Compare a saved baseline package directory against a regenerated one without importing either package:
plumb diff saved-pumps pumps
plumb diff saved-pumps pumps --json > pumps-upgrade.json
plumb diff saved-pumps pumps --check
plumb diff separates contract changes from source, compiler, and
dependency provenance changes. With --check, it exits with status 1 if
any constraint present in both versions lost constructor, runtime, or solver
enforcement (make regen runs this check automatically before publishing).
Extension annotations#
An extension ontology declares its base package in RDF:
@prefix ex: <urn:example:pumps#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix codegen: <https://watermetadata.org/plumb/codegen#> .
ex: a owl:Ontology ;
owl:imports <https://watermetadata.org/ontology/watr> ;
codegen:baseModule "plumb.watr" .
Annotation |
Purpose |
|---|---|
|
Installed Python package providing the base classes |
|
Export a SHACL |
|
Explicit Python name for a class or field |
|
RDF local name for a property, independent of its Python keyword |
Annotations select Python names and projections; all domain rules remain standard OWL and SHACL.
OWL and SHACL → Python mapping#
Ontology / SHACL construct |
Generated Python |
|---|---|
|
|
|
Python inheritance + full |
|
|
|
Descriptor attribute on domain class |
|
Required constructor keyword argument (except cycles & class defaults) |
|
Scalar attribute ( |
|
Type annotation + runtime range/datatype check |
|
Inserted at construction and protected on mutation |
|
Replaceable default at construction |
|
Finite allowed choices enforced on mutation |
|
Inverse attribute kept in sync in memory |
|
Canonicalized to the ontology’s primary namespace |
An extension class has one constructive parent (either from the base package
or another class in the same extension). Contradictory bounds, defaults, or
inherited choices fail at compile time. Loading a saved graph via
Model.from_graph() preserves data as written and never injects defaults.
Named connection points#
A named point is a qualified property shape over s223:hasConnectionPoint
with:
sh:name(the Python attribute name, e.g.inletorsludge),an inlet, outlet, or bidirectional
sh:class,an exact
sh:hasValuemedium and equal positivesh:qualifiedMinCountandsh:qualifiedMaxCount, anddistinguishing facts (such as a fixed
rdfs:label) when multiple points share a direction and medium.
A single point (count == 1) compiles to a PointRef; a group (count > 1)
compiles to a PointGroupRef. Nested sh:and, sh:or, and sh:xone
connection layouts are preserved for the Z3 solver.
Property schemas#
Mark a sh:NodeShape with codegen:projection codegen:PropertySchema. Each
field is a s223:hasProperty shape with a named sh:qualifiedValueShape
IRI, qualified min/max count of 1, and sh:name.
Shape constraint |
Field behavior |
|---|---|
|
Accepts a Python number or |
|
Default value (otherwise required) |
|
Checked on construction |
|
Default unit for bare numbers |
|
Permitted units for |
|
Fixed unit |
|
Preserved label distinguishing fields of the same kind |
|
Displayed by |
Units are verified against QUDT dimension vectors without implicit unit conversion.
Naming rules#
Classes keep their IRI local name (
Air_Handling_Unit).Properties convert camelCase to snake_case (
hasPoint→has_point), except four high-frequency S223 point predicates:hasMedium→medium,isConnectionPointOf→owner,connectsThrough→connection, andpairedConnectionPoint→paired_with.Reserved names owned by
Entity(includingname,type,label,comment,meta,contains,ports,sensor,actuator,quantity,walk,find, …) or Python keywords receive a trailing_.Collisions across IRIs receive
_2,_3, … in deterministic order (deprecated terms are suffixed before current ones, and the ontology’s primary namespace keeps the unsuffixed name).Enumerations live under
enums.valuesas flat names (Fluid_Water) and under branch attributes (enums.Substance.Medium.Mix.Fluid.Water).
Compiler boundaries#
The compiler projects the constructive subset of SHACL into Python; it is
not a general SHACL-SPARQL engine. Complex property paths, non-connection
disjunctions, and SPARQL rules remain enforced by validate() using the
exact bundled _shapes.ttl.