Skip to content

Commit 6aa8377

Browse files
committed
fix: register directory-loaded library files with OntoEnv
_load_shapes_from_directory loaded every file in a library directory straight into the shape collection's graph via Oxigraph's native loader, but never told OntoEnv these ontologies exist. Any owl:imports referencing them - e.g. mediumOffice_constraints.ttl importing urn:ashrae/g36, which guideline36.ttl declares - couldn't be resolved by name, so OntoEnv fell back to treating the import as a relative file path and failed with "No such file or directory". Register each file with the ontology environment alongside the existing bulk graph load. Files without their own owl:Ontology header (guideline36's per-equipment fragments) just get a harmless synthetic name; files that do declare an identity (Brick's imports/*.ttl, which import each other) become resolvable the same way single-file Library.load(ontology_graph=...) already registers them. Verified: without this change, missing_imports() on a graph importing urn:ashrae/g36 reports it as missing after loading the guideline36 directory; with it, the import resolves.
1 parent 0128086 commit 6aa8377

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

buildingmotif/dataclasses/library.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,18 @@ def _load_shapes_from_directory(
376376
f"Could not parse file {filename}: {e}"
377377
)
378378
raise e
379+
# Register the file with OntoEnv under its own declared name (if
380+
# any), independent of the bulk load above. Directory-loaded
381+
# libraries often bundle several files that only make sense
382+
# merged (e.g. guideline36's per-equipment fragments have no
383+
# owl:Ontology header of their own), alongside files that
384+
# declare a real ontology identity and import each other or
385+
# ontologies outside the directory (e.g. Brick's imports/*.ttl).
386+
# Without this, those names are never known to OntoEnv, so any
387+
# owl:imports referencing them - from inside or outside this
388+
# directory - fails to resolve instead of finding the
389+
# already-loaded content.
390+
bm.ontology_environment.add(filename, fetch_imports=False, overwrite=True)
379391
# Native loading does not propagate file prefixes to the rdflib
380392
# namespace manager; restore the standard BuildingMOTIF prefixes so
381393
# serialization stays readable.

0 commit comments

Comments
 (0)