Skip to content

Commit

Permalink
edit parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
muddymudskipper committed Aug 14, 2024
1 parent 984c880 commit 3fa1408
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 44 deletions.
32 changes: 20 additions & 12 deletions cmem_plugin_reason/plugin_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -40,7 +37,6 @@
)

environ["SSL_VERIFY"] = "false"
simplefilter("ignore", category=InsecureRequestWarning)


@Plugin(
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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". '
Expand Down
28 changes: 20 additions & 8 deletions cmem_plugin_reason/plugin_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -40,7 +38,6 @@
)

environ["SSL_VERIFY"] = "false"
simplefilter("ignore", category=InsecureRequestWarning)


@Plugin(
Expand All @@ -52,20 +49,34 @@
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(),
name="md_filename",
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(),
Expand All @@ -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,
Expand Down Expand Up @@ -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)
15 changes: 0 additions & 15 deletions cmem_plugin_reason/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
16 changes: 8 additions & 8 deletions poetry.lock

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

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions tests/test_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3fa1408

Please sign in to comment.