From 3fa14081ff85710891b070baae5665494e4caf00 Mon Sep 17 00:00:00 2001 From: muddymudskipper Date: Wed, 14 Aug 2024 17:55:52 +0100 Subject: [PATCH] edit parameters --- cmem_plugin_reason/plugin_reason.py | 32 +++++++++++++++++---------- cmem_plugin_reason/plugin_validate.py | 28 ++++++++++++++++------- cmem_plugin_reason/utils.py | 15 ------------- poetry.lock | 16 +++++++------- pyproject.toml | 1 - tests/test_reason.py | 1 + 6 files changed, 49 insertions(+), 44 deletions(-) diff --git a/cmem_plugin_reason/plugin_reason.py b/cmem_plugin_reason/plugin_reason.py index f78085f..1144e72 100644 --- a/cmem_plugin_reason/plugin_reason.py +++ b/cmem_plugin_reason/plugin_reason.py @@ -5,7 +5,6 @@ from pathlib import Path from tempfile import TemporaryDirectory from time import time -from warnings import simplefilter import validators.url from cmem.cmempy.dp.proxy.graph import get @@ -19,13 +18,11 @@ from cmem_plugin_base.dataintegration.types import BoolParameterType, StringParameterType from cmem_plugin_base.dataintegration.utils import setup_cmempy_user_access from inflection import underscore -from urllib3.exceptions import InsecureRequestWarning from cmem_plugin_reason.utils import ( MAX_RAM_PERCENTAGE_DEFAULT, MAX_RAM_PERCENTAGE_PARAMETER, ONTOLOGY_GRAPH_IRI_PARAMETER, - OUTPUT_GRAPH_IRI_PARAMETER, REASON_DOC, REASONERS, VALIDATE_PROFILES_PARAMETER, @@ -40,7 +37,6 @@ ) environ["SSL_VERIFY"] = "false" -simplefilter("ignore", category=InsecureRequestWarning) @Plugin( @@ -50,15 +46,27 @@ documentation=REASON_DOC, parameters=[ ONTOLOGY_GRAPH_IRI_PARAMETER, - OUTPUT_GRAPH_IRI_PARAMETER, VALIDATE_PROFILES_PARAMETER, MAX_RAM_PERCENTAGE_PARAMETER, + PluginParameter( + param_type=GraphParameterType( + allow_only_autocompleted_values=False, + classes=[ + "https://vocab.eccenca.com/di/Dataset", + "http://rdfs.org/ns/void#Dataset", + "http://www.w3.org/2002/07/owl#Ontology", + ], + ), + name="output_graph_iri", + label="Output graph IRI", + description="""The IRI of the output graph for the inconsistency validation. ⚠️ Existing + graphs will be overwritten.""", + ), PluginParameter( param_type=ChoiceParameterType(REASONERS), name="reasoner", label="Reasoner", description="Reasoner option. Additionally, select axiom generators below.", - default_value="", ), PluginParameter( param_type=GraphParameterType( @@ -212,10 +220,10 @@ class ReasonPlugin(WorkflowPlugin): def __init__( # noqa: PLR0913 C901 self, - data_graph_iri: str = "", - ontology_graph_iri: str = "", - output_graph_iri: str = "", - reasoner: str = "", + data_graph_iri: str, + ontology_graph_iri: str, + output_graph_iri: str, + reasoner: str, class_assertion: bool = False, data_property_characteristic: bool = False, disjoint_classes: bool = False, @@ -260,9 +268,9 @@ def __init__( # noqa: PLR0913 C901 errors += 'Invalid IRI for parameter "Ontology graph IRI". ' if not validators.url(output_graph_iri): errors += 'Invalid IRI for parameter "Result graph IRI". ' - if output_graph_iri and output_graph_iri == data_graph_iri: + if output_graph_iri == data_graph_iri: errors += "Result graph IRI cannot be the same as the data graph IRI. " - if output_graph_iri and output_graph_iri == ontology_graph_iri: + if output_graph_iri == ontology_graph_iri: errors += "Result graph IRI cannot be the same as the ontology graph IRI. " if reasoner not in REASONERS: errors += 'Invalid value for parameter "Reasoner". ' diff --git a/cmem_plugin_reason/plugin_validate.py b/cmem_plugin_reason/plugin_validate.py index c81dc8f..b0d127b 100644 --- a/cmem_plugin_reason/plugin_validate.py +++ b/cmem_plugin_reason/plugin_validate.py @@ -5,7 +5,6 @@ from pathlib import Path from tempfile import TemporaryDirectory from time import time -from warnings import simplefilter import validators.url from cmem.cmempy.dp.proxy.graph import get @@ -14,18 +13,17 @@ from cmem_plugin_base.dataintegration.description import Icon, Plugin, PluginParameter from cmem_plugin_base.dataintegration.entity import Entities, Entity, EntityPath, EntitySchema from cmem_plugin_base.dataintegration.parameter.choice import ChoiceParameterType +from cmem_plugin_base.dataintegration.parameter.graph import GraphParameterType from cmem_plugin_base.dataintegration.plugins import WorkflowPlugin from cmem_plugin_base.dataintegration.ports import FixedNumberOfInputs, FixedSchemaPort from cmem_plugin_base.dataintegration.types import BoolParameterType, StringParameterType from cmem_plugin_base.dataintegration.utils import setup_cmempy_user_access from pathvalidate import is_valid_filename -from urllib3.exceptions import InsecureRequestWarning from cmem_plugin_reason.utils import ( MAX_RAM_PERCENTAGE_DEFAULT, MAX_RAM_PERCENTAGE_PARAMETER, ONTOLOGY_GRAPH_IRI_PARAMETER, - OUTPUT_GRAPH_IRI_PARAMETER, REASONERS, VALIDATE_DOC, VALIDATE_PROFILES_PARAMETER, @@ -40,7 +38,6 @@ ) environ["SSL_VERIFY"] = "false" -simplefilter("ignore", category=InsecureRequestWarning) @Plugin( @@ -52,13 +49,26 @@ ONTOLOGY_GRAPH_IRI_PARAMETER, MAX_RAM_PERCENTAGE_PARAMETER, VALIDATE_PROFILES_PARAMETER, - OUTPUT_GRAPH_IRI_PARAMETER, + PluginParameter( + param_type=GraphParameterType( + allow_only_autocompleted_values=False, + classes=[ + "https://vocab.eccenca.com/di/Dataset", + "http://rdfs.org/ns/void#Dataset", + "http://www.w3.org/2002/07/owl#Ontology", + ], + ), + name="output_graph_iri", + label="Output graph IRI", + description="""The IRI of the output graph for the inconsistency validation. ⚠️ Existing + graphs will be overwritten.""", + default_value="", + ), PluginParameter( param_type=ChoiceParameterType(REASONERS), name="reasoner", label="Reasoner", description="Reasoner option.", - default_value="", ), PluginParameter( param_type=StringParameterType(), @@ -66,6 +76,7 @@ label="Output filename", description="The filename of the Markdown file with the explanation of " "inconsistencies.⚠️ Existing files will be overwritten.", + default_value="", ), PluginParameter( param_type=BoolParameterType(), @@ -91,8 +102,8 @@ class ValidatePlugin(WorkflowPlugin): def __init__( # noqa: PLR0913 C901 self, - ontology_graph_iri: str = "", - reasoner: str = "elk", + ontology_graph_iri: str, + reasoner: str, output_graph_iri: str = "", md_filename: str = "", validate_profile: bool = False, @@ -268,5 +279,6 @@ def execute(self, inputs: None, context: ExecutionContext) -> Entities | None: operation_desc="ontologies validated.", ) ) + with TemporaryDirectory() as self.temp: return self._execute(context) diff --git a/cmem_plugin_reason/utils.py b/cmem_plugin_reason/utils.py index 17b7dfb..9eeafa8 100644 --- a/cmem_plugin_reason/utils.py +++ b/cmem_plugin_reason/utils.py @@ -65,21 +65,6 @@ default_value=False, ) -OUTPUT_GRAPH_IRI_PARAMETER = PluginParameter( - param_type=GraphParameterType( - allow_only_autocompleted_values=False, - classes=[ - "https://vocab.eccenca.com/di/Dataset", - "http://rdfs.org/ns/void#Dataset", - "http://www.w3.org/2002/07/owl#Ontology", - ], - ), - name="output_graph_iri", - label="Output graph IRI", - description="""The IRI of the output graph for the inconsistency validation. ⚠️ Existing graphs - graphs will be overwritten.""", -) - def create_xml_catalog_file(dir_: str, graphs: dict) -> None: """Create XML catalog file""" diff --git a/poetry.lock b/poetry.lock index 2d5c841..4669b19 100644 --- a/poetry.lock +++ b/poetry.lock @@ -126,13 +126,13 @@ colorama = {version = "*", markers = "platform_system == \"Windows\""} [[package]] name = "cmem-cmempy" -version = "24.1.1" +version = "24.2.0" description = "API for eccenca Corporate Memory" optional = false python-versions = "<4.0,>=3.9" files = [ - {file = "cmem_cmempy-24.1.1-py3-none-any.whl", hash = "sha256:a335823a39518ba69ea07c3f047e567d6e80f75dd2e50f8b2afe73f7d0f056da"}, - {file = "cmem_cmempy-24.1.1.tar.gz", hash = "sha256:659ef5206dc7dd07a9cd8c9da98a8f5e6353cad397e5859dc418bc1684cb6eb6"}, + {file = "cmem_cmempy-24.2.0-py3-none-any.whl", hash = "sha256:0ceb9454ee88338ddb12d295ffbe5ecb86bd0d233dac23a72af865e8fa8c2202"}, + {file = "cmem_cmempy-24.2.0.tar.gz", hash = "sha256:3996f9d2dbe5d946525b70439858312208d83ceb87db5672979e9e8a84e4d19e"}, ] [package.dependencies] @@ -1064,18 +1064,18 @@ setuptools = "*" [[package]] name = "setuptools" -version = "72.1.0" +version = "72.2.0" description = "Easily download, build, install, upgrade, and uninstall Python packages" optional = false python-versions = ">=3.8" files = [ - {file = "setuptools-72.1.0-py3-none-any.whl", hash = "sha256:5a03e1860cf56bb6ef48ce186b0e557fdba433237481a9a625176c2831be15d1"}, - {file = "setuptools-72.1.0.tar.gz", hash = "sha256:8d243eff56d095e5817f796ede6ae32941278f542e0f941867cc05ae52b162ec"}, + {file = "setuptools-72.2.0-py3-none-any.whl", hash = "sha256:f11dd94b7bae3a156a95ec151f24e4637fb4fa19c878e4d191bfb8b2d82728c4"}, + {file = "setuptools-72.2.0.tar.gz", hash = "sha256:80aacbf633704e9c8bfa1d99fa5dd4dc59573efcf9e4042c13d3bcef91ac2ef9"}, ] [package.extras] core = ["importlib-metadata (>=6)", "importlib-resources (>=5.10.2)", "jaraco.text (>=3.7)", "more-itertools (>=8.8)", "ordered-set (>=3.1.1)", "packaging (>=24)", "platformdirs (>=2.6.2)", "tomli (>=2.0.1)", "wheel (>=0.43.0)"] -doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "pyproject-hooks (!=1.1)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier"] +doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "pyproject-hooks (!=1.1)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier", "towncrier (<24.7)"] test = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "importlib-metadata", "ini2toml[lite] (>=0.14)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "jaraco.test", "mypy (==1.11.*)", "packaging (>=23.2)", "pip (>=19.1)", "pyproject-hooks (!=1.1)", "pytest (>=6,!=8.1.*)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-home (>=0.5)", "pytest-mypy", "pytest-perf", "pytest-ruff (<0.4)", "pytest-ruff (>=0.2.1)", "pytest-ruff (>=0.3.2)", "pytest-subprocess", "pytest-timeout", "pytest-xdist (>=3)", "tomli", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] [[package]] @@ -1167,4 +1167,4 @@ crypto-eth-addresses = ["eth-hash[pycryptodome] (>=0.7.0)"] [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "4df369a43e71446c9cbc562df56387e5f6607d84851c42188d3799874a8848bf" +content-hash = "aaa6d9426e01b3085332ea743e18779f30ff5fec6c0521b42203d4de17618458" diff --git a/pyproject.toml b/pyproject.toml index 9e6ef0c..42d9f3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,6 @@ python = "^3.11" validators = "^0.33.0" pathvalidate = "^3.2.0" defusedxml = "^0.7.1" -urllib3 = "^2.2.2" inflection = "^0.5.1" [tool.poetry.dependencies.cmem-plugin-base] diff --git a/tests/test_reason.py b/tests/test_reason.py index e03d807..0ecab00 100644 --- a/tests/test_reason.py +++ b/tests/test_reason.py @@ -90,6 +90,7 @@ def test_validate(errors: str) -> str: result = ValidatePlugin( ontology_graph_iri=VALIDATE_ONTOLOGY_GRAPH_IRI, output_graph_iri=OUTPUT_GRAPH_IRI, + reasoner="elk", validate_profile=True, md_filename=MD_FILENAME, output_entities=True,