diff --git a/CHANGELOG.md b/CHANGELOG.md index 59ef909..9dee8a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,15 +6,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## [Unreleased] - ### Added - defined input and output schema +### Fixed + + - incorrect stopping of workflow if "validate_profiles" and "stop_at_inconsistencies" is enabled in Validate plugin + ### Changed - raise OSError on post result graph error - removed write_md and produce_graph bool parameters +- if "input_profiles" is enabled the Reason plugin expects ontology_iri and "profile" non the input. +The ontologi iri on the input overrides the plugin setting. ## [1.0.0beta4] 2024-07-12 diff --git a/cmem_plugin_reason/plugin_reason.py b/cmem_plugin_reason/plugin_reason.py index e038815..e7ff194 100644 --- a/cmem_plugin_reason/plugin_reason.py +++ b/cmem_plugin_reason/plugin_reason.py @@ -294,12 +294,25 @@ def get_graphs(self, graphs: dict, context: ExecutionContext) -> None: def reason(self, graphs: dict) -> None: """Reason""" + # remove_query = f""" + # SELECT ?s ?p ?o + # WHERE {{ + # ?s <{self.output_graph_iri}> . + # }} + # """ + # filtered_file = Path(self.temp) / "filtered_triples.owl" + # query_file = Path(self.temp) / "remove.rq" + # with query_file.open("w") as rqfile: + # rqfile.write(remove_query) + axioms = " ".join(k for k, v in self.axioms.items() if v) data_location = f"{self.temp}/{graphs[self.data_graph_iri]}" utctime = str(datetime.fromtimestamp(int(time()), tz=UTC))[:-6].replace(" ", "T") + "Z" cmd = ( f'merge --input "{data_location}" ' "--collapse-import-closure false " + # f'--query query.sparql {filtered_file} ' + # f'remove --input "{data_location}" --input {filtered_file} --select "triples" ' f"reason --reasoner {self.reasoner} " f'--axiom-generators "{axioms}" ' f"--include-indirect true " @@ -341,7 +354,9 @@ def post_valid_profiles(self, inputs: Sequence[Entities], graphs: dict) -> None: def _execute(self, inputs: Sequence[Entities], context: ExecutionContext) -> None: """`Execute plugin""" setup_cmempy_user_access(context.user) - graphs = get_graphs_tree((self.data_graph_iri, self.ontology_graph_iri)) + graphs = get_graphs_tree( + (self.data_graph_iri, self.ontology_graph_iri, self.output_graph_iri) + ) self.get_graphs(graphs, context) create_xml_catalog_file(self.temp, graphs) self.reason(graphs) diff --git a/cmem_plugin_reason/plugin_validate.py b/cmem_plugin_reason/plugin_validate.py index a2ba36b..8fadaf9 100644 --- a/cmem_plugin_reason/plugin_validate.py +++ b/cmem_plugin_reason/plugin_validate.py @@ -208,7 +208,7 @@ def make_entities(self, text: str, valid_profiles: list) -> Entities: def _execute(self, context: ExecutionContext) -> Entities: """Run the workflow operator.""" setup_cmempy_user_access(context.user) - graphs = get_graphs_tree((self.ontology_graph_iri,)) + graphs = get_graphs_tree((self.ontology_graph_iri, self.output_graph_iri)) self.get_graphs(graphs, context) create_xml_catalog_file(self.temp, graphs) self.explain(graphs) diff --git a/cmem_plugin_reason/utils.py b/cmem_plugin_reason/utils.py index 37c4fe6..1e49cab 100644 --- a/cmem_plugin_reason/utils.py +++ b/cmem_plugin_reason/utils.py @@ -86,15 +86,15 @@ def create_xml_catalog_file(dir_: str, graphs: dict) -> None: def get_graphs_tree(graph_iris: tuple) -> dict: - """Get graph import tree""" + """Get graph import tree. Last item in tuple is output_graph_iri which is excluded""" graphs = {} - for graph_iri in graph_iris: + for graph_iri in graph_iris[:-1]: if graph_iri not in graphs: graphs[graph_iri] = f"{token_hex(8)}.nt" tree = get_graph_import_tree(graph_iri) for value in tree["tree"].values(): for iri in value: - if iri not in graphs: + if iri not in graphs and iri != graph_iri[-1]: graphs[iri] = f"{token_hex(8)}.nt" return graphs