From 0941889630b2798392b9c6cada19a85004db2729 Mon Sep 17 00:00:00 2001 From: manonBlanco <blanco@teklia.com> Date: Fri, 24 Nov 2023 10:13:38 +0100 Subject: [PATCH] Apply suggestions --- nerval/evaluate.py | 7 ++----- tests/test_parse_bio.py | 3 +-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/nerval/evaluate.py b/nerval/evaluate.py index 7a1d2c4..0efe5b4 100644 --- a/nerval/evaluate.py +++ b/nerval/evaluate.py @@ -309,10 +309,7 @@ def run(annotation: Path, prediction: Path, threshold: int, verbose: bool) -> di # Get string and list of labels per character def read_file(path: Path) -> List[str]: assert path.exists(), f"Error: Input file {path} does not exist" - - with open(path, "r") as fd: - lines = list(filter(lambda x: x != "\n", fd.readlines())) - return lines + return path.read_text().strip().splitlines() logger.info(f"Parsing file @ {annotation}") annot = parse_bio(read_file(annotation)) @@ -320,7 +317,7 @@ def run(annotation: Path, prediction: Path, threshold: int, verbose: bool) -> di logger.info(f"Parsing file @ {prediction}") predict = parse_bio(read_file(prediction)) - if not annot or not predict: + if not (annot and predict): raise Exception("No content found in annotation or prediction files.") scores = evaluate(annot, predict, threshold) diff --git a/tests/test_parse_bio.py b/tests/test_parse_bio.py index 71868fc..1089795 100644 --- a/tests/test_parse_bio.py +++ b/tests/test_parse_bio.py @@ -179,8 +179,7 @@ expected_parsed_end_of_file = { ], ) def test_parse_bio(test_input, expected): - with open(test_input, "r") as fd: - lines = list(filter(lambda x: x != "\n", fd.readlines())) + lines = test_input.read_text().strip().splitlines() assert evaluate.parse_bio(lines) == expected -- GitLab