Skip to content
Snippets Groups Projects
Commit c844e024 authored by Eva Bardou's avatar Eva Bardou :frog: Committed by Yoann Schneider
Browse files

Utils method to print a Markdown table

parent 917410f5
No related branches found
No related tags found
1 merge request!39Utils method to print a Markdown table
...@@ -5,7 +5,6 @@ from typing import List ...@@ -5,7 +5,6 @@ from typing import List
import editdistance import editdistance
import edlib import edlib
from prettytable import MARKDOWN, PrettyTable
from nerval.parse import ( from nerval.parse import (
BEGINNING_POS, BEGINNING_POS,
...@@ -15,7 +14,7 @@ from nerval.parse import ( ...@@ -15,7 +14,7 @@ from nerval.parse import (
look_for_further_entity_part, look_for_further_entity_part,
parse_bio, parse_bio,
) )
from nerval.utils import print_result_compact, print_results from nerval.utils import print_mardown_table, print_result_compact, print_results
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -391,16 +390,9 @@ def run_multiple(file_csv: Path, folder: Path, threshold: int, verbose: bool): ...@@ -391,16 +390,9 @@ def run_multiple(file_csv: Path, folder: Path, threshold: int, verbose: bool):
raise Exception("No file were counted") raise Exception("No file were counted")
logger.info("Average score on all corpus") logger.info("Average score on all corpus")
table = PrettyTable() result = [
table.field_names = ["Precision", "Recall", "F1"] round(precision / count, 3),
table.set_style(MARKDOWN) round(recall / count, 3),
table.add_rows( round(f1 / count, 3),
[ ]
[ print_mardown_table(["Precision", "Recall", "F1"], [result])
round(precision / count, 3),
round(recall / count, 3),
round(f1 / count, 3),
],
],
)
print(table)
from prettytable import MARKDOWN, PrettyTable from prettytable import MARKDOWN, PrettyTable
def print_mardown_table(header: list[str], rows: list[list]):
table = PrettyTable()
table.field_names = header
table.set_style(MARKDOWN)
table.add_rows(rows)
print(table)
def print_results(scores: dict): def print_results(scores: dict):
"""Display final results. """Display final results.
None values are kept to indicate the absence of a certain tag in either annotation or prediction. None values are kept to indicate the absence of a certain tag in either annotation or prediction.
""" """
header = ["tag", "predicted", "matched", "Precision", "Recall", "F1", "Support"]
results = [] results = []
for tag in sorted(scores, reverse=True): for tag in sorted(scores, reverse=True):
prec = None if scores[tag]["P"] is None else round(scores[tag]["P"], 3) prec = None if scores[tag]["P"] is None else round(scores[tag]["P"], 3)
...@@ -25,29 +32,23 @@ def print_results(scores: dict): ...@@ -25,29 +32,23 @@ def print_results(scores: dict):
], ],
) )
table = PrettyTable() print_mardown_table(
table.field_names = header ["tag", "predicted", "matched", "Precision", "Recall", "F1", "Support"],
table.set_style(MARKDOWN) results,
table.add_rows(results) )
print(table)
def print_result_compact(scores: dict): def print_result_compact(scores: dict):
header = ["tag", "predicted", "matched", "Precision", "Recall", "F1", "Support"]
result = [ result = [
[ "All",
"All", scores["All"]["predicted"],
scores["All"]["predicted"], scores["All"]["matched"],
scores["All"]["matched"], round(scores["All"]["P"], 3),
round(scores["All"]["P"], 3), round(scores["All"]["R"], 3),
round(scores["All"]["R"], 3), round(scores["All"]["F1"], 3),
round(scores["All"]["F1"], 3), scores["All"]["Support"],
scores["All"]["Support"],
],
] ]
print_mardown_table(
table = PrettyTable() ["tag", "predicted", "matched", "Precision", "Recall", "F1", "Support"],
table.field_names = header [result],
table.set_style(MARKDOWN) )
table.add_rows(result)
print(table)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment