Skip to content

Commit

Permalink
fix Reason parameter provenance, new iri for plugin in provenance data
Browse files Browse the repository at this point in the history
  • Loading branch information
muddymudskipper committed Jul 2, 2024
1 parent f835bf6 commit dfac802
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 14 additions & 0 deletions cmem_plugin_reason/plugin_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,20 @@ def __init__( # noqa: PLR0913
sub_object_property: bool = False,
max_ram_percentage: int = MAX_RAM_PERCENTAGE_DEFAULT,
) -> None:
self.sub_class = sub_class
self.equivalent_class = equivalent_class
self.disjoint_classes = disjoint_classes
self.data_property_characteristic = data_property_characteristic
self.equivalent_data_properties = equivalent_data_properties
self.sub_data_property = sub_data_property
self.class_assertion = class_assertion
self.property_assertion = property_assertion
self.equivalent_object_property = equivalent_object_property
self.inverse_object_properties = inverse_object_properties
self.object_property_characteristic = object_property_characteristic
self.sub_object_property = sub_object_property
self.object_property_range = object_property_range
self.object_property_domain = object_property_domain
self.axioms = {
"SubClass": sub_class,
"EquivalentClass": equivalent_class,
Expand Down
14 changes: 10 additions & 4 deletions cmem_plugin_reason/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import unicodedata
from collections import OrderedDict
from pathlib import Path
from secrets import token_hex
from shutil import rmtree
from xml.etree.ElementTree import Element, SubElement, tostring

Expand Down Expand Up @@ -128,9 +129,10 @@ def post_provenance(plugin: WorkflowPlugin, context: ExecutionContext) -> None:
project_graph = f"http://di.eccenca.com/project/{context.task.project_id()}"

type_query = f"""
SELECT ?type {{
SELECT ?type ?label {{
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 @@ -142,6 +144,7 @@ def post_provenance(plugin: WorkflowPlugin, context: ExecutionContext) -> None:
except IndexError:
plugin.log.warning("Could not add provenance data to output graph.")
return
plugin_label = result["results"]["bindings"][0]["label"]["value"]

param_split = (
plugin_type.replace(
Expand All @@ -159,17 +162,20 @@ def post_provenance(plugin: WorkflowPlugin, context: ExecutionContext) -> None:
}}
}}"""

new_plugin_iri = f'{"_".join(plugin_iri.split("_")[:-1])}_{token_hex(8)}'
result = json.loads(post_select(query=parameter_query))
param_sparql = f"<{plugin_iri}> a <{plugin_type}> . "
param_sparql = ""
for binding in result["results"]["bindings"]:
param_iri = binding["parameter"]["value"]
param_val = plugin.__dict__[binding["parameter"]["value"].split(param_split)[1]]
param_sparql += f'\n<{plugin_iri}> <{param_iri}> "{param_val}" . '
param_sparql += f'\n<{new_plugin_iri}> <{param_iri}> "{param_val}" .'

insert_query = f"""
INSERT DATA {{
GRAPH <{plugin.output_graph_iri}> {{
<{plugin.output_graph_iri}> <http://www.w3.org/ns/prov#wasGeneratedBy> <{plugin_iri}> .
<{plugin.output_graph_iri}> <http://www.w3.org/ns/prov#wasGeneratedBy> <{new_plugin_iri}> .
<{new_plugin_iri}> a <{plugin_type}>, <https://vocab.eccenca.com/di/CustomTask> .
<{new_plugin_iri}> <http://www.w3.org/2000/01/rdf-schema#label> "{plugin_label}" .
{param_sparql}
}}
}}"""
Expand Down

0 comments on commit dfac802

Please sign in to comment.