Skip to content

Commit

Permalink
fixing import bug
Browse files Browse the repository at this point in the history
  • Loading branch information
muddymudskipper committed Jul 26, 2024
1 parent fe56b95 commit 4d81367
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 16 additions & 1 deletion cmem_plugin_reason/plugin_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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 Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmem_plugin_reason/plugin_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions cmem_plugin_reason/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4d81367

Please sign in to comment.