From c1f88dd0bf614d2e250b36ada45cb7aefa794f48 Mon Sep 17 00:00:00 2001 From: Gabe Fierro Date: Mon, 2 Dec 2024 22:26:57 -0700 Subject: [PATCH] fix use of shacl path --- buildingmotif/dataclasses/validation.py | 5 +++-- buildingmotif/ingresses/naming_convention.py | 16 ++++++++++------ .../ingresses/semantic_graph_synthesis.py | 5 ----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/buildingmotif/dataclasses/validation.py b/buildingmotif/dataclasses/validation.py index 0b557791b..033bdb8fd 100644 --- a/buildingmotif/dataclasses/validation.py +++ b/buildingmotif/dataclasses/validation.py @@ -8,6 +8,7 @@ import rdflib from pyshacl.helper.path_helper import shacl_path_to_sparql_path +from pyshacl.shapes_graph import ShapesGraph from rdflib import Graph, URIRef from rdflib.collection import Collection from rdflib.term import BNode, Node @@ -224,7 +225,7 @@ def reason(self) -> str: """Human-readable explanation of this GraphDiff.""" # interpret a SHACL property path as a sparql property path path = shacl_path_to_sparql_path( - self.graph, self.path, prefixes=dict(self.graph.namespaces()) + ShapesGraph(self.graph), self.path, prefixes=dict(self.graph.namespaces()) ) classname = self.graph.qname(self.classname) @@ -402,7 +403,7 @@ def from_validation_report(cls, report: Graph) -> List["RequiredPath"]: def reason(self) -> str: """Human-readable explanation of this GraphDiff.""" path = shacl_path_to_sparql_path( - self.graph, self.path, prefixes=dict(self.graph.namespaces()) + ShapesGraph(self.graph), self.path, prefixes=dict(self.graph.namespaces()) ) return self.format_count_error(self.maxc, self.minc, path) diff --git a/buildingmotif/ingresses/naming_convention.py b/buildingmotif/ingresses/naming_convention.py index 9e1f1fc8d..25f961ea9 100644 --- a/buildingmotif/ingresses/naming_convention.py +++ b/buildingmotif/ingresses/naming_convention.py @@ -34,17 +34,21 @@ def __init__( self.naming_convention = naming_convention def dump_failed_labels(self): - sorted_groups = sorted( - analyze_failures(self.failures).items(), - key=lambda x: len(x[1]), - reverse=True, - ) - for group, failures in sorted_groups: + for group, failures in self.sorted_failures: print(f"Unparsed label: {group} ({len(failures)} failures)") for failure in failures: print(f"\t{failure}") print() + @property + def sorted_failures(self) -> list: + return sorted( + analyze_failures(self.failures).items(), + key=lambda x: len(x[1]), + reverse=True, + ) + + @cached_property def records(self) -> List[Record]: results, failures = parse_list( diff --git a/buildingmotif/ingresses/semantic_graph_synthesis.py b/buildingmotif/ingresses/semantic_graph_synthesis.py index 6cb92da15..c58d0054c 100644 --- a/buildingmotif/ingresses/semantic_graph_synthesis.py +++ b/buildingmotif/ingresses/semantic_graph_synthesis.py @@ -61,11 +61,6 @@ def graph(self, ns: Namespace) -> Graph: graph = ev.body else: graph = ev - # remove all triples where either the subject or object is in the PARAM namespace - for s, p, o in graph: - if str(s).startswith(str(ns.PARAM)) or str(o).startswith(str(ns.PARAM)): - logger.info(f"Removing triple {s} {p} {o}") - graph.remove((s, p, o)) logger.info(f"Adding graph with {len(graph)} triples to output") g += graph return g