diff --git a/nerval/evaluate.py b/nerval/evaluate.py index 7a1d2c4b6bb69ee899c8560379b19e50282977ad..0efe5b4a53cd4c8fabfa9dad884e10e92c6df99f 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 71868fca8e62183d114e396171e7c579ea7154ea..10897953bde5caa825ea0070fd558d6498eb6f18 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