From ac6c34002ac87a7999ab9c85c7f20a840f50b32a Mon Sep 17 00:00:00 2001
From: Charlotte Mauvezin <charlotte.mauvezin@irht.cnrs.fr>
Date: Tue, 4 Jan 2022 12:08:00 +0000
Subject: [PATCH] Adding a line with the mean total for the precision, the
 recall and the f1...

---
 nerval/evaluate.py | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/nerval/evaluate.py b/nerval/evaluate.py
index ab11dde..2f0070d 100644
--- a/nerval/evaluate.py
+++ b/nerval/evaluate.py
@@ -514,7 +514,6 @@ def run(annotation: str, prediction: str, threshold: int, verbose: bool) -> dict
 
     Each measure is given at document level, global score is a micro-average across entity types.
     """
-
     # Get string and list of labels per character
     annot = parse_bio(annotation)
     predict = parse_bio(prediction)
@@ -570,6 +569,10 @@ def run_multiple(file_csv, folder, threshold, verbose):
     if os.path.isdir(folder):
         list_bio_file = glob.glob(str(folder) + "/**/*.bio", recursive=True)
 
+        count = 0
+        precision = 0
+        recall = 0
+        f1 = 0
         for row in list_cor:
             annot = None
             predict = None
@@ -582,11 +585,24 @@ def run_multiple(file_csv, folder, threshold, verbose):
                     predict = file
 
             if annot and predict:
+                count += 1
                 print(os.path.basename(predict))
-                run(annot, predict, threshold, verbose)
+                scores = run(annot, predict, threshold, verbose)
+                precision += scores["All"]["P"]
+                recall += scores["All"]["R"]
+                f1 += scores["All"]["F1"]
                 print()
             else:
-                raise f"No file found for files {annot}, {predict}"
+                raise Exception(f"No file found for files {annot}, {predict}")
+        if count:
+            print(
+                "Average scores in all corpus (mean of final files scores)\n"
+                f" * Precision: {round(precision/count, 3)}\n"
+                f" * Recall: {round(recall/count, 3)}\n"
+                f" * F1: {round(f1/count, 3)}\n"
+            )
+        else:
+            raise Exception("No file were counted")
     else:
         raise Exception("the path indicated does not lead to a folder.")
 
-- 
GitLab