Skip to content

Commit

Permalink
fix interactions with shacl inference
Browse files Browse the repository at this point in the history
  • Loading branch information
gtfierro committed Mar 12, 2024
1 parent cdeba72 commit 95cee3f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 36 deletions.
2 changes: 1 addition & 1 deletion buildingmotif/dataclasses/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def _load_from_ontology(
# expand the ontology graph before we insert it into the database. This will ensure
# that the output of compiled models will not contain triples that really belong to
# the ontology
shacl_inference(ontology, ontology)
ontology = shacl_inference(ontology)

lib = cls.create(ontology_name, overwrite=overwrite)

Expand Down
11 changes: 9 additions & 2 deletions buildingmotif/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ def shacl_validate(
:type data_graph: Graph
:param shape_graph: the shape graph to validate against
:type shape_graph: Graph, optional
:param engine: the SHACL engine to use, defaults to "topquadrant"
:type engine: str, optional
:return: a tuple containing the validation result, the validation report, and the validation report string
:rtype: Tuple[bool, Graph, str]
"""

if engine == "topquadrant":
Expand All @@ -571,8 +575,8 @@ def shacl_validate(


def shacl_inference(
data_graph: Graph, shape_graph: Optional[Graph], engine="topquadrant"
):
data_graph: Graph, shape_graph: Optional[Graph] = None, engine="topquadrant"
) -> Graph:
"""
Infer new triples in the data graph using the shape graph.
Edits the data graph in place. Uses the fastest inference method available.
Expand All @@ -585,6 +589,8 @@ def shacl_inference(
:type shape_graph: Optional[Graph]
:param engine: the SHACL engine to use, defaults to "topquadrant"
:type engine: str, optional
:return: the data graph with inferred triples
:rtype: Graph
"""
if engine == "topquadrant":
try:
Expand All @@ -606,3 +612,4 @@ def shacl_inference(
js=True,
allow_warnings=True,
)
return data_graph
60 changes: 30 additions & 30 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ setuptools = "^65.6.3"
psycopg2 = {version="^2.9.5", optional=true}
pygit2 = "~1.11.1"
jsonschema = "^4.21.1"
brick-tq-shacl = {optional = true, version="0.2.0"}
brick-tq-shacl = {optional = true, version="0.3.1a3"}
werkzeug="^2.3.7"

[tool.poetry.group.dev.dependencies]
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_template_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import warnings
from rdflib import Graph, Namespace

from buildingmotif import BuildingMOTIF
Expand Down Expand Up @@ -198,9 +199,9 @@ def test_template_evaluate_with_optional(bm: BuildingMOTIF):
assert t.parameters == {"occ"}

# assert no warning is raised when optional args are not required
with pytest.warns(None) as record:
with warnings.catch_warnings():
warnings.simplefilter("error")
t = templ.evaluate({"name": BLDG["vav"]})
assert len(record) == 0

with pytest.warns():
partial_templ = templ.evaluate(
Expand Down

0 comments on commit 95cee3f

Please sign in to comment.