Skip to content

Commit

Permalink
Fixing compilation (#59)
Browse files Browse the repository at this point in the history
* progress

* remove ontoenv dir

* update deps
  • Loading branch information
gtfierro authored Jan 18, 2025
1 parent ca56792 commit 5e962b1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
6 changes: 1 addition & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
22 changes: 10 additions & 12 deletions tools/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
import string
import random
import argparse
import ontoenv
import rdflib
#import brickschema
#from brickschema import topquadrant_shacl
from brick_tq_shacl.topquadrant_shacl import infer, validate
import rdflib

graph = rdflib.Graph()
cfg = ontoenv.Config(["models", "ontologies"], offline=False, strict=False)
env = ontoenv.OntoEnv(cfg)

if __name__ == "__main__":
parser = argparse.ArgumentParser(
Expand All @@ -30,28 +33,23 @@

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():
graph.bind(prefix, uri)
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))

0 comments on commit 5e962b1

Please sign in to comment.