Skip to content

Commit

Permalink
handle prefixes whe nconverting to sparql paths
Browse files Browse the repository at this point in the history
  • Loading branch information
gtfierro committed Nov 11, 2024
1 parent f251eb3 commit 9cd0055
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions buildingmotif/dataclasses/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from buildingmotif import get_building_motif
from buildingmotif.dataclasses.shape_collection import ShapeCollection
from buildingmotif.namespaces import CONSTRAINT, PARAM, RDF, SH, A
from buildingmotif.namespaces import CONSTRAINT, PARAM, RDF, SH, A, bind_prefixes
from buildingmotif.utils import (
_gensym,
_guarantee_unique_template_name,
Expand Down Expand Up @@ -42,6 +42,9 @@ class GraphDiff:
validation_result: Graph
graph: Graph

def __post_init__(self):
bind_prefixes(self.graph)

def resolve(self, lib: "Library") -> List["Template"]:
"""Produces a list of templates to resolve this GraphDiff.
Expand Down Expand Up @@ -184,7 +187,7 @@ def from_validation_report(cls, report: Graph) -> List["PathClassCount"]:
def reason(self) -> str:
"""Human-readable explanation of this GraphDiff."""
# interpret a SHACL property path as a sparql property path
path = self.graph.qname(shacl_path_to_sparql_path(self.graph, self.path))
path = shacl_path_to_sparql_path(self.graph, self.path, prefixes=dict(self.graph.namespaces()))

classname = self.graph.qname(self.classname)
if self.maxc is None and self.minc is not None:
Expand Down Expand Up @@ -374,7 +377,7 @@ def from_validation_report(cls, report: Graph) -> List["RequiredPath"]:

def reason(self) -> str:
"""Human-readable explanation of this GraphDiff."""
path = self.graph.qname(shacl_path_to_sparql_path(self.graph, self.path))
path = shacl_path_to_sparql_path(self.graph, self.path, prefixes=dict(self.graph.namespaces()))
if self.maxc is None and self.minc is not None:
return f"{self.focus} needs at least {self.minc} uses of path {path}"
if self.minc is None and self.maxc is not None:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/api/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def test_validate_model(client, building_motif, shacl_engine):
)

# Assert
assert results.status_code == 200
assert results.status_code == 200, results.data

assert results.get_json().keys() == {"message", "reasons", "valid"}
assert isinstance(results.get_json()["message"], str)
Expand All @@ -304,7 +304,7 @@ def test_validate_model(client, building_motif, shacl_engine):
)

# Assert
assert results.status_code == 200
assert results.status_code == 200, results.data

assert results.get_json().keys() == {"message", "reasons", "valid"}
assert isinstance(results.get_json()["message"], str)
Expand Down

0 comments on commit 9cd0055

Please sign in to comment.