Skip to content
Snippets Groups Projects
Commit c8d4cf6e authored by Manon Blanco's avatar Manon Blanco
Browse files

Add a message to assertion errors

parent 63851d7c
No related branches found
No related tags found
1 merge request!40Add a message to assertion errors
Pipeline #155143 failed
......@@ -58,10 +58,10 @@ def compute_matches(
Output : {TAG1 : nb_entity_matched, ...}, example : {'All': 1, 'OCC': 0, 'PER': 1}
"""
assert annotation
assert prediction
assert labels_annot
assert labels_predict
assert annotation, "Annotation is empty"
assert prediction, "Prediction is empty"
assert labels_annot, "Annotation labels are empty"
assert labels_predict, "Prediction labels are empty"
entity_count = {"All": 0}
last_tag = NOT_ENTITY_TAG
......@@ -190,9 +190,9 @@ def get_labels_aligned(original: str, aligned: str, labels_original: list) -> li
Output format :
list of strings
"""
assert original
assert aligned
assert labels_original
assert original, "Original is empty"
assert aligned, "Aligned is empty"
assert labels_original, "Original labels are empty"
labels_aligned = []
index_original = 0
......
......@@ -42,7 +42,7 @@ def parse_line(index: int, line: str):
try:
match_iob = REGEX_IOB_LINE.search(line)
assert match_iob
assert match_iob, f"Line {line} does not match IOB regex"
return match_iob.group(1, 2)
except AssertionError:
......@@ -149,10 +149,14 @@ def parse_bio(lines: List[str]) -> dict:
result["labels"] = labels
result["entity_count"] = entity_count
assert len(result["words"]) == len(result["labels"])
assert len(result["words"]) == len(
result["labels"]
), f'Found {len(result["words"])} word(s) for {len(result["labels"])} label(s)'
for tag in result["entity_count"]:
if tag != "All":
assert result["labels"].count(f"B-{tag}") == result["entity_count"][tag]
assert (
result["labels"].count(f"B-{tag}") == result["entity_count"][tag]
), f'Found {result["entity_count"][tag]} entities for {result["labels"].count(f"B-{tag}")} label(s) for entity {tag}'
return result
......
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