Skip to content

Commit

Permalink
fix error when result graph is imported in input graph
Browse files Browse the repository at this point in the history
  • Loading branch information
muddymudskipper committed Aug 7, 2024
1 parent 4d81367 commit e2aad78
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 108 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Fixed

- incorrect stopping of workflow if "validate_profiles" and "stop_at_inconsistencies" is enabled in Validate plugin
- fixed error when output graph is imported by input graph; the import is removed in-memory before reasoning

### 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.
- if "input_profiles" is enabled the Reason plugin expects "ontology_iri" and "profile" on the input.
The ontology IRI on the input overrides the plugin setting.

## [1.0.0beta4] 2024-07-12

Expand Down
24 changes: 8 additions & 16 deletions cmem_plugin_reason/plugin_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,34 +285,26 @@ def get_graphs(self, graphs: dict, context: ExecutionContext) -> None:
self.log.info(f"Fetching graph {graph}.")
with (Path(self.temp) / graphs[graph]).open("w", encoding="utf-8") as file:
setup_cmempy_user_access(context.user)
file.write(get(graph).text)
for line in get(graph).text.splitlines():
if line != (
f"<{graph}> <http://www.w3.org/2002/07/owl#imports> "
f"<{self.output_graph_iri}> ."
):
file.write(line + "\n")
if graph == self.data_graph_iri:
file.write(
f"\n<{graph}> "
f"<http://www.w3.org/2002/07/owl#imports> <{self.ontology_graph_iri}> ."
f"<{graph}> <http://www.w3.org/2002/07/owl#imports> "
f"<{self.ontology_graph_iri}> ."
)

def reason(self, graphs: dict) -> None:
"""Reason"""
# remove_query = f"""
# SELECT ?s ?p ?o
# WHERE {{
# ?s <http://www.w3.org/2002/07/owl#imports> <{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 "
Expand Down
Loading

0 comments on commit e2aad78

Please sign in to comment.