diff --git a/CHANGELOG.md b/CHANGELOG.md index cfc9061..19d68d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Added - Compatibility with cmem-plugin-base v4 -- Added parameter "Remove additional graph types from data graph" +- Parameters for removing additionnal graph types from the data graph" ### Fixed diff --git a/README-public.md b/README-public.md index 6389c9f..f88251f 100644 --- a/README-public.md +++ b/README-public.md @@ -77,11 +77,6 @@ If enabled, OWL inferencing expansion of the data graph is performed before vali Enable SHACL Advanced Features. Default value: *false*. -### Remove additional graph types from data graph - -Before validating, remove graph types that may have been added by CMEM to the data graph. Removes triples of the form ` a `, where `` is one -of ``, ``, ``. Default value: *false*. - ## Parameter Input In order to set options via the input the following parameter names can be used: @@ -102,5 +97,4 @@ In order to set options via the input the following parameter names can be used: | Meta-SHACL | meta_shacl | | Ontology graph URI | ontology_graph_uri | | Inference | inference | -| SHACL Advanced Features | advanced | -| Remove additional graph types from data graph | remove_graph_types | \ No newline at end of file +| SHACL Advanced Features | advanced | \ No newline at end of file diff --git a/README.md b/README.md index bcf7895..d5839d6 100644 --- a/README.md +++ b/README.md @@ -79,11 +79,6 @@ If enabled, OWL inferencing expansion of the data graph is performed before vali Enable SHACL Advanced Features. Default value: *false*. -### Remove additional graph types from data graph - -Before validating, remove graph types that may have been added by CMEM to the data graph. Removes triples of the form ` a `, where `` is one -of ``, ``, ``. Default value: *false*. - ## Parameter Input In order to set options via the input the following parameter names can be used: @@ -105,4 +100,3 @@ In order to set options via the input the following parameter names can be used: | Ontology graph URI | ontology_graph_uri | | Inference | inference | | SHACL Advanced Features | advanced | -| Remove additional graph types from data graph | remove_graph_types | \ No newline at end of file diff --git a/cmem_plugin_pyshacl/plugin_pyshacl.py b/cmem_plugin_pyshacl/plugin_pyshacl.py index d78f672..2495312 100644 --- a/cmem_plugin_pyshacl/plugin_pyshacl.py +++ b/cmem_plugin_pyshacl/plugin_pyshacl.py @@ -275,13 +275,32 @@ def langfilter(lbl): ), PluginParameter( param_type=BoolParameterType(), - name="remove_graph_types", - label="Remove additional graph types from data graph", - description="Before validating, remove graph types that may have been " - "added by CMEM to the data graph. Removes triples of the form a " - ", where type is one of , " - ", " - ".", + name="remove_dataset_graph_type", + label="Remove graph type from data graph", + description="Before validating, remove the triple a " + " from the loaded data graph.", + default_value=False, + advanced=True, + ), + PluginParameter( + param_type=BoolParameterType(), + name="remove_thesaurus_graph_type", + label="Remove graph type " + "from data graph", + description="Before validating, remove the triple a " + " from the loaded data " + "graph.", + default_value=False, + advanced=True, + ), + PluginParameter( + param_type=BoolParameterType(), + name="remove_shape_catalog_graph_type", + label="Remove graph type " + "from data graph", + description="Before validating, remove the triple a " + " from the loaded data " + "graph.", default_value=False, advanced=True, ), @@ -312,7 +331,9 @@ def __init__( meta_shacl, inference, advanced, - remove_graph_types, + remove_dataset_graph_type, + remove_thesaurus_graph_type, + remove_shape_catalog_graph_type, ) -> None: self.data_graph_uri = data_graph_uri self.shacl_graph_uri = shacl_graph_uri @@ -329,7 +350,9 @@ def __init__( self.meta_shacl = meta_shacl self.inference = inference self.advanced = advanced - self.remove_graph_types = remove_graph_types + self.remove_dataset_graph_type = remove_dataset_graph_type + self.remove_thesaurus_graph_type = remove_thesaurus_graph_type + self.remove_shape_catalog_graph_type = remove_shape_catalog_graph_type discover_plugins_in_module("cmem_plugin_pyshacl") this_plugin = Plugin.plugins[0] @@ -655,6 +678,13 @@ def check_parameters(self): for param in self.graph_parameters + self.bool_parameters: self.log.info(f"{param}: {self.__dict__[param]}") + def remove_graph_type(self, data_graph, iri): + """ + Remove triple a + """ + self.log.info(f"Removing graph type <{iri}> from data graph") + data_graph.remove((URIRef(self.data_graph_uri), RDF.type, URIRef(iri))) + def execute(self, inputs=(), context: ExecutionContext = ExecutionContext()): """ execute plugin @@ -672,15 +702,16 @@ def execute(self, inputs=(), context: ExecutionContext = ExecutionContext()): data_graph = self.get_graph(self.data_graph_uri) self.log.info(f"Finished loading data graph in {e_t(start)} seconds") - if self.remove_graph_types: - self.log.info("Removing additional graph types from data graph") - graph_type_iris = [ - "http://rdfs.org/ns/void#Dataset", - "https://vocab.eccenca.com/shui/ShapeCatalog", - "https://vocab.eccenca.com/dsm/ThesaurusProject", - ] - for iri in graph_type_iris: - data_graph.remove((URIRef(self.data_graph_uri), RDF.type, URIRef(iri))) + if self.remove_dataset_graph_type: + self.remove_graph_type(data_graph, "http://rdfs.org/ns/void#Dataset") + if self.remove_thesaurus_graph_type: + self.remove_graph_type( + data_graph, "https://vocab.eccenca.com/dsm/ThesaurusProject" + ) + if self.remove_shape_catalog_graph_type: + self.remove_graph_type( + data_graph, "https://vocab.eccenca.com/shui/ShapeCatalog" + ) self.log.info(f"Loading SHACL graph <{self.shacl_graph_uri}> into memory...") start = time() diff --git a/tests/test_pyshacl.py b/tests/test_pyshacl.py index 12f8dd2..eb47b3e 100644 --- a/tests/test_pyshacl.py +++ b/tests/test_pyshacl.py @@ -48,10 +48,12 @@ def test_workflow_execution(): add_labels=True, include_graphs_labels=True, add_shui_conforms=True, - meta_shacl=False, - inference="none", - advanced=False, - remove_graph_types=False, + meta_shacl=True, + inference="both", + advanced=True, + remove_dataset_graph_type=True, + remove_thesaurus_graph_typ=True, + remove_shape_catalog_graph_type=True, ) plugin.execute(inputs=(), context=TestExecutionContext()) res = get(validation_graph_uri)