Skip to content
Snippets Groups Projects
Commit d506b249 authored by Manon Blanco's avatar Manon Blanco Committed by Yoann Schneider
Browse files

Use early returns

parent fa980bce
No related branches found
No related tags found
1 merge request!36Use early returns
Pipeline #150436 passed
......@@ -349,48 +349,49 @@ def run_multiple(file_csv: Path, folder: Path, threshold: int, verbose: bool):
csv_reader = reader(read_obj)
list_cor = list(csv_reader)
if folder.is_dir():
list_bio_file = list(folder.rglob("*.bio"))
count = 0
precision = 0
recall = 0
f1 = 0
for row in list_cor:
annot = None
predict = None
for file in list_bio_file:
if row[0] == file.name:
annot = file
for file in list_bio_file:
if row[1] == file.name:
predict = file
if annot and predict:
count += 1
scores = run(annot, predict, threshold, verbose)
precision += scores["All"]["P"]
recall += scores["All"]["R"]
f1 += scores["All"]["F1"]
else:
raise Exception(f"No file found for files {row[0]}, {row[1]}")
if count:
logger.info("Average score on all corpus")
table = PrettyTable()
table.field_names = ["Precision", "Recall", "F1"]
table.set_style(MARKDOWN)
table.add_rows(
[
[
round(precision / count, 3),
round(recall / count, 3),
round(f1 / count, 3),
],
],
)
print(table)
else:
raise Exception("No file were counted")
else:
raise Exception("the path indicated does not lead to a folder.")
if not folder.is_dir():
raise Exception("The path indicated does not lead to a folder.")
list_bio_file = list(folder.rglob("*.bio"))
count = 0
precision = 0
recall = 0
f1 = 0
for row in list_cor:
annot = None
predict = None
for file in list_bio_file:
if row[0] == file.name:
annot = file
for file in list_bio_file:
if row[1] == file.name:
predict = file
if not (annot and predict):
raise Exception(f"No file found for files {row[0]}, {row[1]}")
count += 1
scores = run(annot, predict, threshold, verbose)
precision += scores["All"]["P"]
recall += scores["All"]["R"]
f1 += scores["All"]["F1"]
if not count:
raise Exception("No file were counted")
logger.info("Average score on all corpus")
table = PrettyTable()
table.field_names = ["Precision", "Recall", "F1"]
table.set_style(MARKDOWN)
table.add_rows(
[
[
round(precision / count, 3),
round(recall / count, 3),
round(f1 / count, 3),
],
],
)
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