Skip to content

Commit

Permalink
create plugin label in provenance data
Browse files Browse the repository at this point in the history
  • Loading branch information
muddymudskipper committed Aug 30, 2024
1 parent 06aa83b commit 7956a20
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Changed

- output graph label derived from input graph
- create plugin label in provenance data

## [1.0.0rc1] 2024-08-28

Expand Down
2 changes: 1 addition & 1 deletion cmem_plugin_reason/plugin_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def _execute(self, context: ExecutionContext) -> None:
else:
valid_profiles = validate_profiles(self, graphs)
post_profiles(self, valid_profiles)
post_provenance(self, get_provenance(self, context))
post_provenance(self, get_provenance(self, "Reason", context))

if self.import_result or not self.import_ontology:
setup_cmempy_user_access(context.user)
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 @@ -253,7 +253,7 @@ def _execute(self, context: ExecutionContext) -> Entities | None:
setup_cmempy_user_access(context.user)
send_result(self.output_graph_iri, Path(self.temp) / "output.ttl")
setup_cmempy_user_access(context.user)
post_provenance(self, get_provenance(self, context))
post_provenance(self, get_provenance(self, "Validate", context))

valid_profiles = (
self.add_profiles(validate_profiles(self, graphs)) if self.validate_profile else []
Expand Down
11 changes: 6 additions & 5 deletions cmem_plugin_reason/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,19 @@ def post_provenance(plugin: WorkflowPlugin, prov: dict | None) -> None:
post_update(query=insert_query)


def get_provenance(plugin: WorkflowPlugin, context: ExecutionContext) -> dict | None:
def get_provenance(
plugin: WorkflowPlugin, label_plugin: str, context: ExecutionContext
) -> dict | None:
"""Get provenance information"""
plugin_iri = (
f"http://dataintegration.eccenca.com/{context.task.project_id()}/{context.task.task_id()}"
)
project_graph = f"http://di.eccenca.com/project/{context.task.project_id()}"

type_query = f"""
SELECT ?type ?label {{
SELECT ?type {{
GRAPH <{project_graph}> {{
<{plugin_iri}> a ?type .
<{plugin_iri}> <http://www.w3.org/2000/01/rdf-schema#label> ?label .
FILTER(STRSTARTS(STR(?type), "https://vocab.eccenca.com/di/functions/"))
}}
}}
Expand All @@ -160,7 +161,6 @@ def get_provenance(plugin: WorkflowPlugin, context: ExecutionContext) -> dict |
except IndexError:
plugin.log.warning("Could not add provenance data to output graph.")
return None
plugin_label = result["results"]["bindings"][0]["label"]["value"]

param_split = (
plugin_type.replace(
Expand All @@ -180,11 +180,12 @@ def get_provenance(plugin: WorkflowPlugin, context: ExecutionContext) -> dict |
"""

new_plugin_iri = f'{"_".join(plugin_iri.split("_")[:-1])}_{token_hex(8)}'
label = f"{label_plugin} plugin"
result = json.loads(post_select(query=parameter_query))

prov = {
"plugin_iri": new_plugin_iri,
"plugin_label": plugin_label,
"plugin_label": label,
"plugin_type": plugin_type,
"parameters": {},
}
Expand Down
44 changes: 22 additions & 22 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7956a20

Please sign in to comment.