Skip to content

Commit

Permalink
use ontology IRI from input if input_profiles=True
Browse files Browse the repository at this point in the history
  • Loading branch information
muddymudskipper committed Jul 26, 2024
1 parent 70e4ce5 commit d6735f0
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions cmem_plugin_reason/plugin_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def __init__( # noqa: PLR0913, C901
self.input_ports = FixedNumberOfInputs([FixedSchemaPort(self.generate_input_schema())])
else:
self.input_ports = FixedNumberOfInputs([])
self.output_port = FixedSchemaPort(EntitySchema(type_uri="", paths=[]))
self.output_port = None

def generate_input_schema(self) -> EntitySchema:
"""Generate the output schema."""
Expand Down Expand Up @@ -354,17 +354,26 @@ def _execute(self, inputs: Sequence[Entities], context: ExecutionContext) -> Non
def execute(self, inputs: Sequence[Entities], context: ExecutionContext) -> None:
"""Validate input, execute plugin with temporary directory"""
if self.input_profiles:
errors = ""
values = next(inputs[0].entities).values
paths = [p.path for p in inputs[0].schema.paths]
if not inputs:
raise OSError(
'Input entities needed if "Process valid OWL profiles from input" is enabled'
)
if "profile" not in paths or "ontology" not in paths:
raise ValueError("Invalid input for processing OWL profiles")
if values[paths.index("ontology")][0] != self.ontology_graph_iri:
raise ValueError(
"The ontology IRI validated with Validate differs from the input ontology IRI."
)
if "profile" not in paths:
errors += 'No value for "profile" given on input. '
if "ontology" not in paths:
errors += 'No value for "ontology" given on input. '
self.ontology_graph_iri = values[paths.index("ontology")][0]
if not validators.url(self.ontology_graph_iri):
errors += 'Invalid IRI for parameter "Ontology graph IRI". '
if self.ontology_graph_iri == self.data_graph_iri:
errors += "Ontology graph IRI cannot be the same as the data graph IRI. "
if self.ontology_graph_iri == self.output_graph_iri:
errors += "Ontology graph IRI cannot be the same as the output graph IRI. "
if errors:
raise ValueError(errors[:-1])

with TemporaryDirectory() as self.temp:
self._execute(inputs, context)

0 comments on commit d6735f0

Please sign in to comment.