From f2cf4eea06e3db4b4b186a0d41ec9c3439d4af02 Mon Sep 17 00:00:00 2001 From: manonBlanco <blanco@teklia.com> Date: Thu, 8 Aug 2024 12:45:52 +0200 Subject: [PATCH] Evaluation: Return the displayed rows --- nerval/utils.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/nerval/utils.py b/nerval/utils.py index fbfa5d1..ba0dc02 100644 --- a/nerval/utils.py +++ b/nerval/utils.py @@ -2,8 +2,10 @@ from prettytable import MARKDOWN, PrettyTable from nerval import ALL_ENTITIES +TABLE_HEADER = ["tag", "predicted", "matched", "Precision", "Recall", "F1", "Support"] -def print_markdown_table(header: list[str], rows: list[list]) -> None: + +def print_markdown_table(header: list[str], rows: list[list]) -> list[list]: """Prints a Markdown table filled with the provided header and rows.""" table = PrettyTable() table.field_names = header @@ -26,8 +28,10 @@ def print_markdown_table(header: list[str], rows: list[list]) -> None: table.add_rows(rows) print(table) + return rows + -def print_results(scores: dict) -> None: +def print_results(scores: dict) -> list[list]: """Display final results. None values are kept to indicate the absence of a certain tag in either annotation or prediction. @@ -50,13 +54,10 @@ def print_results(scores: dict) -> None: ], ) - print_markdown_table( - ["tag", "predicted", "matched", "Precision", "Recall", "F1", "Support"], - results, - ) + return print_markdown_table(TABLE_HEADER, results) -def print_result_compact(scores: dict) -> None: +def print_result_compact(scores: dict) -> list[list]: result = [ ALL_ENTITIES, scores[ALL_ENTITIES]["predicted"], @@ -66,7 +67,5 @@ def print_result_compact(scores: dict) -> None: round(scores[ALL_ENTITIES]["F1"], 3), scores[ALL_ENTITIES]["Support"], ] - print_markdown_table( - ["tag", "predicted", "matched", "Precision", "Recall", "F1", "Support"], - [result], - ) + + return print_markdown_table(TABLE_HEADER, [result]) -- GitLab