diff --git a/src/annotation_mapping.py b/src/annotation_mapping.py deleted file mode 100644 index 3a06c9c2c517d1b4b6b2ae7f5e13c5913fe5211e..0000000000000000000000000000000000000000 --- a/src/annotation_mapping.py +++ /dev/null @@ -1,55 +0,0 @@ -from typing import Dict, List, Tuple, TypeVar - -T1 = TypeVar("T1") -T2 = TypeVar("T2") - - -def map_annotatios( - ref_annotations: List[Tuple[int, int, T1]], - all_annotations: Dict[str, List[Tuple[int, int, T2]]], - target_columns: List[str], -) -> Dict[Tuple[int, int, T1], Dict[str, Tuple[int, int, T2]]]: - """Map annotations from target columns to reference annotations. - - Example: - >> ref_annotations = [(0, 3, "Andrzej"), (7, 11, "psa")] - >> all_annotations = { - >> "A": [(0, 3, "Andrzej"), (7, 11, "psa")], - >> "B": [(0, 3, "AndrzejB"), (7, 11, "psaA")], - >> "C": [(0, 3, "AndrzejC"), (8, 9, "psaC")], - >> } - >> target_columns = ["B", "C"] - >> map_annotatios(ref_annotations, all_annotations, target_columns) - { - (0, 3, "Andrzej"): {"B": (0, 3, "AndrzejB"), "C": (0, 3, "AndrzejC")}, - (7, 11, "psa"): { - "B": (7, 11, "psaA"), - }, - } - - Args: - ref_annotations (List[Tuple[int, int, T1]]): Reference annotations. - all_annotations (Dict[str, List[Tuple[int, int, T2]]]): All annotations. - target_columns (List[str]): Target columns. - - Returns: - Dict[Tuple[int, int, T1], Dict[str, Tuple[int, int, T2]]]: Mapped annotations. - """ - - result = dict() - index_map = dict() - - for s_start, s_end, s_anno in ref_annotations: - result[(s_start, s_end, s_anno)] = dict() - index_map[(s_start, s_end)] = (s_start, s_end, s_anno) - - for target_column in target_columns: - for t_start, t_end, t_anno in all_annotations[target_column]: - if (t_start, t_end) in index_map: - result[index_map[(t_start, t_end)]][target_column] = ( - t_start, - t_end, - t_anno, - ) - - return result diff --git a/src/input_parsers/wiktor_ner.py b/src/input_parsers/wiktor_ner.py index 463f32f0a0815b63edd7ac5218ef7128c3f87bc3..14e195df987b0ba1dedcf8c3e0a19a46a99d62ed 100644 --- a/src/input_parsers/wiktor_ner.py +++ b/src/input_parsers/wiktor_ner.py @@ -1,9 +1,6 @@ -from typing import Dict, List, Tuple -from lxml import etree +from typing import List, Tuple import json -from collections import defaultdict -# from src.annotation_types_old import from src.input_parsers.interface import InputParser from src.annotations import Annotation, MorphosyntacticAnnotation, NerAnnotation diff --git a/tests/unit/input_parsers/test_ccl.py b/tests/unit/input_parsers/test_ccl.py index 80cc4f2f3e78cd37345a2c85bbe7bf0666f0b323..6032503eacc7803dfa2a50ea25d8cd203ed0fd47 100644 --- a/tests/unit/input_parsers/test_ccl.py +++ b/tests/unit/input_parsers/test_ccl.py @@ -1,6 +1,4 @@ -# from src.annotation_types_old import AnnotationTypes from src.input_parsers.ccl import CCLInputParser -from tempfile import NamedTemporaryFile from src.annotations import NerAnnotation, MorphosyntacticAnnotation example_ccl = """<?xml version="1.0" encoding="UTF-8"?> diff --git a/tests/unit/input_parsers/test_wiktor_ner.py b/tests/unit/input_parsers/test_wiktor_ner.py index 25e928b4dfc4010dbbb5446da7bd3ae24a5e5f11..04d8bf389fa4d62de51f57e9e995d879ae399de9 100644 --- a/tests/unit/input_parsers/test_wiktor_ner.py +++ b/tests/unit/input_parsers/test_wiktor_ner.py @@ -1,4 +1,3 @@ -# from src.annotation_types_old import AnnotationTypes from src.input_parsers.wiktor_ner import WiktorNERInputParser from src.annotations import NerAnnotation, MorphosyntacticAnnotation diff --git a/tests/unit/test_annotation_mapping.py b/tests/unit/test_annotation_mapping.py deleted file mode 100644 index a43133df461e227012f1163a67a12fa9fd06eccc..0000000000000000000000000000000000000000 --- a/tests/unit/test_annotation_mapping.py +++ /dev/null @@ -1,20 +0,0 @@ -from src.annotation_mapping import map_annotatios - - -def test_map_annotations(): - ref_annotations = [(0, 3, "Andrzej"), (7, 11, "psa")] - all_annotations = { - "A": [(0, 3, "Andrzej"), (7, 11, "psa")], - "B": [(0, 3, "AndrzejB"), (7, 11, "psaA")], - "C": [(0, 3, "AndrzejC"), (8, 9, "psaC")], - } - - result = map_annotatios(ref_annotations, all_annotations, ["B", "C"]) - excepted = { - (0, 3, "Andrzej"): {"B": (0, 3, "AndrzejB"), "C": (0, 3, "AndrzejC")}, - (7, 11, "psa"): { - "B": (7, 11, "psaA"), - }, - } - - assert result == excepted