From 5e962b1208fa5f24a30cb6b632738525046f7b59 Mon Sep 17 00:00:00 2001 From: Gabe Fierro Date: Sat, 18 Jan 2025 16:48:55 -0700 Subject: [PATCH] Fixing compilation (#59) * progress * remove ontoenv dir * update deps --- Makefile | 11 +++++++---- pyproject.toml | 6 +----- tools/compile.py | 22 ++++++++++------------ 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index ffc5836..e89a6e5 100644 --- a/Makefile +++ b/Makefile @@ -10,13 +10,16 @@ MODEL_SOURCES := $(wildcard models/*.ttl) # COMPILED_MODELS will be the list of files but in the models/compiled folder. COMPILED_MODELS := $(patsubst models/%.ttl,models/compiled/%.ttl,$(MODEL_SOURCES)) +.ontoenv: + ontoenv init models ontologies + # Rule to compile each model. # The prerequisite 'models/%.ttl' means it will match each .ttl file in the models directory. # 'tools/compile.py' ensures the compile script is present, but should be a prerequisite only if you want to track changes on it. # 'ontologies/*.ttl' captures changes in any .ttl file in the ontologies directory. -models/compiled/%.ttl: models/%.ttl tools/compile.py - -python tools/compile.py -r -i -o $@ $< - #ontologies/223p.ttl +models/compiled/%.ttl: models/%.ttl tools/compile.py .ontoenv + ontoenv refresh + -uv run python tools/compile.py -r -i -o $@ $< # The compile-models target will "make" all of the COMPILED_MODELS. compile-models: $(COMPILED_MODELS) @@ -26,4 +29,4 @@ install-kernel: # Rule to clean up the compiled models. clean: - rm -f models/compiled/*.ttl + rm -rf models/compiled/*.ttl .ontoenv diff --git a/pyproject.toml b/pyproject.toml index c45f1c4..7fd23c4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,15 +10,11 @@ dependencies = [ "jupyter-book>=1.0.2", "jupyterlab>=4.2.5", "nbformat>=5.10.4", - "pyontoenv>=0.1.9", + "pyontoenv>=0.1.10a7", "rdflib>=7.0.0", "sphinxcontrib-mermaid>=0.9.2", "toml>=0.10.2", ] -[build-system] -requires = ["hatchling"] -build-backend = "hatchling.build" - [tool.uv.sources] buildingmotif = { git = "https://github.com/NREL/buildingmotif.git", rev = "develop" } diff --git a/tools/compile.py b/tools/compile.py index af96bde..7beda08 100644 --- a/tools/compile.py +++ b/tools/compile.py @@ -2,6 +2,7 @@ import string import random import argparse +import ontoenv import rdflib #import brickschema #from brickschema import topquadrant_shacl @@ -9,6 +10,8 @@ import rdflib graph = rdflib.Graph() +cfg = ontoenv.Config(["models", "ontologies"], offline=False, strict=False) +env = ontoenv.OntoEnv(cfg) if __name__ == "__main__": parser = argparse.ArgumentParser( @@ -30,20 +33,15 @@ namespaces = dict(graph.namespace_manager.namespaces()) - s223 = rdflib.Graph() - if args.do_import: - s223.parse("ontologies/223p.ttl") - namespaces.update(dict(s223.namespace_manager.namespaces())) - - # remove QUDT prefix because it breaks things - #graph.bind("qudtprefix21", rdflib.Namespace("http://qudt.org/2.1/vocab/prefix/")) - #graph.bind("qudtprefix", rdflib.Namespace("http://qudt.org/vocab/prefix/")) + deps = rdflib.Graph() + env.get_closure("http://data.ashrae.org/standard223/1.0/model/all", deps) + env.import_dependencies(graph) + deps.serialize("deps.ttl", format="turtle") + graph.serialize("graph.ttl", format="turtle") if args.reason: - graph.remove((None, rdflib.OWL.imports, None)) - s223.remove((None, rdflib.OWL.imports, None)) #topquadrant_shacl._MAX_EXTERNAL_LOOPS = 2 - graph = infer(graph, s223) + graph = infer(graph, graph) #graph.expand(profile="shacl", backend="topquadrant") if args.output: for prefix, uri in namespaces.items(): @@ -51,7 +49,7 @@ graph.serialize(args.output, format="turtle") else: print(graph.serialize(format="turtle")) - valid, _, report = validate(graph, s223) + valid, _, report = validate(graph, graph) if not valid: print(report) raise Exception("Validation failed: {}".format(report))