Skip to content

Commit

Permalink
init ExecutionReport
Browse files Browse the repository at this point in the history
  • Loading branch information
muddymudskipper committed Aug 8, 2024
1 parent a8b5ca5 commit 8e6120d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
6 changes: 6 additions & 0 deletions cmem_plugin_reason/plugin_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ 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"""
context.report.update(
ExecutionReport(
operation="reason",
operation_desc="ontologies and data graphs processed.",
)
)
if self.input_profiles:
errors = ""
values = next(inputs[0].entities).values
Expand Down
32 changes: 20 additions & 12 deletions cmem_plugin_reason/plugin_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ def __init__( # noqa: PLR0913
self.schema = self.generate_output_schema()
self.output_port = FixedSchemaPort(self.schema)

def generate_output_schema(self) -> EntitySchema:
"""Generate the output schema."""
paths = [EntityPath(path="markdown"), EntityPath(path="ontology")]
if self.validate_profile:
paths.append(EntityPath(path="profile"))
return EntitySchema(
type_uri="https://eccenca.com/plugin_validateontology/type",
paths=paths,
)

def get_graphs(self, graphs: dict, context: ExecutionContext) -> None:
"""Get graphs from CMEM"""
for graph in graphs:
Expand Down Expand Up @@ -189,16 +199,6 @@ def add_profiles(self, valid_profiles: list) -> list:
post_profiles(self, valid_profiles)
return valid_profiles

def generate_output_schema(self) -> EntitySchema:
"""Generate the output schema."""
paths = [EntityPath(path="markdown"), EntityPath(path="ontology")]
if self.validate_profile:
paths.append(EntityPath(path="profile"))
return EntitySchema(
type_uri="https://eccenca.com/plugin_validateontology/type",
paths=paths,
)

def make_entities(self, text: str, valid_profiles: list) -> Entities:
"""Make entities"""
values = [[text], [self.ontology_graph_iri]]
Expand Down Expand Up @@ -240,11 +240,13 @@ def _execute(self, context: ExecutionContext) -> Entities:
context.report.update(
ExecutionReport(
operation="validate",
error="Inconsistencies found in ontology",
error="Inconsistencies found in ontology.",
operation_desc="ontologies processed.",
entity_count=1,
)
)
else:
self.log.warning("Inconsistencies found in ontology")
self.log.warning("Inconsistencies found in ontology.")
else:
context.report.update(
ExecutionReport(
Expand All @@ -258,5 +260,11 @@ def _execute(self, context: ExecutionContext) -> Entities:

def execute(self, inputs: tuple, context: ExecutionContext) -> Entities: # noqa: ARG002
"""Remove temp files on error"""
context.report.update(
ExecutionReport(
operation="validate",
operation_desc="ontologies validated.",
)
)
with TemporaryDirectory() as self.temp:
return self._execute(context)

0 comments on commit 8e6120d

Please sign in to comment.