Skip to content

Commit

Permalink
use dcterms for provenance and random temp filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
muddymudskipper committed Jul 9, 2024
1 parent e63d18c commit 696a5b2
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 33 deletions.
5 changes: 2 additions & 3 deletions cmem_plugin_reason/plugin_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,8 @@ def reason(self, graphs: dict) -> None:
f"--language-annotation rdfs:comment "
f'"Reasoning result set of <{self.data_graph_iri}> and '
f'<{self.ontology_graph_iri}>" en '
f'--link-annotation prov:wasDerivedFrom "{self.data_graph_iri}" '
f"--link-annotation prov:wasDerivedFrom "
f'"{self.ontology_graph_iri}" '
f'--link-annotation dc:source "{self.data_graph_iri}" '
f'--link-annotation dc:source "{self.ontology_graph_iri}" '
f'--typed-annotation dc:created "{utctime}" xsd:dateTime '
f'--output "{self.temp}/result.ttl"'
)
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 @@ -156,7 +156,7 @@ def explain(self, graphs: dict) -> None:
f'--language-annotation rdfs:label "Ontology Validation Result {utctime}" en '
f"--language-annotation rdfs:comment "
f'"Ontology validation of <{self.ontology_graph_iri}>" en '
f'--link-annotation prov:wasDerivedFrom "{self.ontology_graph_iri}" '
f'--link-annotation dc:source "{self.ontology_graph_iri}" '
f'--typed-annotation dc:created "{utctime}" xsd:dateTime '
f'--output "{self.temp}/output.ttl"'
)
Expand Down
18 changes: 3 additions & 15 deletions cmem_plugin_reason/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""Common constants and functions"""

import json
import re
import shlex
import unicodedata
from collections import OrderedDict
from pathlib import Path
from secrets import token_hex
Expand Down Expand Up @@ -70,16 +68,6 @@
)


def convert_iri_to_filename(value: str) -> str:
"""Convert IRI to filename"""
value = unicodedata.normalize("NFKD", value).encode("ascii", "ignore").decode("ascii")
value = re.sub(r"\.", "_", value.lower())
value = re.sub(r"/", "_", value.lower())
value = re.sub(r"[^\w\s-]", "", value.lower())
value = re.sub(r"[-\s]+", "-", value).strip("-_")
return value + ".nt"


def create_xml_catalog_file(dir_: str, graphs: dict) -> None:
"""Create XML catalog file"""
file_name = Path(dir_) / "catalog-v001.xml"
Expand All @@ -102,12 +90,12 @@ def get_graphs_tree(graph_iris: tuple) -> dict:
graphs = {}
for graph_iri in graph_iris:
if graph_iri not in graphs:
graphs[graph_iri] = convert_iri_to_filename(graph_iri)
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:
graphs[iri] = convert_iri_to_filename(iri)
graphs[iri] = f"{token_hex(8)}.nt"
return graphs


Expand All @@ -132,7 +120,7 @@ def post_provenance(plugin: WorkflowPlugin, prov: dict | None) -> None:
insert_query = f"""
INSERT DATA {{
GRAPH <{plugin.output_graph_iri}> {{
<{plugin.output_graph_iri}> <http://www.w3.org/ns/prov#wasGeneratedBy>
<{plugin.output_graph_iri}> <http://purl.org/dc/terms/creator>
<{prov["plugin_iri"]}> .
<{prov["plugin_iri"]}> a <{prov["plugin_type"]}>,
<https://vocab.eccenca.com/di/CustomTask> .
Expand Down
4 changes: 2 additions & 2 deletions tests/test_elk.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix dc: <http://purl.org/dc/terms/> .
@prefix vocab: <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/> .
@base <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/result/> .

<https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/result/> rdf:type owl:Ontology ;
owl:imports vocab: ;
rdfs:comment "Reasoning result set of <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/data/> and <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/>"@en ;
prov:wasDerivedFrom
dc:source
<https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/data/> , <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/> .

#################################################################
Expand Down
4 changes: 2 additions & 2 deletions tests/test_emr.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix dc: <http://purl.org/dc/terms/> .
@prefix vocab: <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/> .
@base <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/result/> .

<https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/result/> rdf:type owl:Ontology ;
owl:imports vocab: ;
rdfs:comment "Reasoning result set of <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/data/> and <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/>"@en ;
prov:wasDerivedFrom
dc:source
<https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/data/> , <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/> .

#################################################################
Expand Down
4 changes: 2 additions & 2 deletions tests/test_hermit.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix dc: <http://purl.org/dc/terms/> .
@prefix vocab: <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/> .
@base <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/result/> .

<https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/result/> rdf:type owl:Ontology ;
owl:imports vocab: ;
rdfs:comment "Reasoning result set of <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/data/> and <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/>"@en ;
prov:wasDerivedFrom
dc:source
<https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/data/> , <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/> .

#################################################################
Expand Down
4 changes: 2 additions & 2 deletions tests/test_jfact.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix dc: <http://purl.org/dc/terms/> .
@prefix vocab: <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/> .
@base <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/result/> .

<https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/result/> rdf:type owl:Ontology ;
owl:imports vocab: ;
rdfs:comment "Reasoning result set of <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/data/> and <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/>"@en ;
prov:wasDerivedFrom
dc:source
<https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/data/> , <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/> .

#################################################################
Expand Down
4 changes: 2 additions & 2 deletions tests/test_structural.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix dc: <http://purl.org/dc/terms/> .
@prefix vocab: <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/> .
@base <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/result/> .

<https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/result/> rdf:type owl:Ontology ;
owl:imports vocab: ;
rdfs:comment "Reasoning result set of <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/data/> and <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/>"@en ;
prov:wasDerivedFrom
dc:source
<https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/data/> , <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/> .

#################################################################
Expand Down
4 changes: 2 additions & 2 deletions tests/test_validate_output.ttl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix dc: <http://purl.org/dc/terms/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .


<https://ns.eccenca.com/validateontology/e02aaed014c94e0c91bf960fed127750/output/> a owl:Ontology ;
rdfs:comment "Ontology validation of <https://ns.eccenca.com/validateontology/e02aaed014c94e0c91bf960fed127750/vocab/>"@en ;
prov:wasDerivedFrom <https://ns.eccenca.com/validateontology/e02aaed014c94e0c91bf960fed127750/vocab/> .
dc:source <https://ns.eccenca.com/validateontology/e02aaed014c94e0c91bf960fed127750/vocab/> .

<https://ns.eccenca.com/validateontology/e02aaed014c94e0c91bf960fed127750/vocab/D_6> a owl:NamedIndividual,
<https://ns.eccenca.com/validateontology/e02aaed014c94e0c91bf960fed127750/vocab/A> .
Expand Down
4 changes: 2 additions & 2 deletions tests/test_whelk.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix dc: <http://purl.org/dc/terms/> .
@prefix vocab: <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/> .
@base <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/result/> .

<https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/result/> rdf:type owl:Ontology ;
owl:imports vocab: ;
rdfs:comment "Reasoning result set of <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/data/> and <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/>"@en ;
prov:wasDerivedFrom
dc:source
<https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/data/> , <https://ns.eccenca.com/reasoning/e02aaed014c94e0c91bf960fed127750/vocab/> .

#################################################################
Expand Down

0 comments on commit 696a5b2

Please sign in to comment.