Skip to content
Snippets Groups Projects
Commit 831cf50b authored by Michał Pogoda's avatar Michał Pogoda
Browse files

Remove unused code

parent 4f663e3c
3 merge requests!10Anonimizer v2,!8Add txt output format,!7Better coverage
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
from typing import Dict, List, Tuple from typing import List, Tuple
from lxml import etree
import json import json
from collections import defaultdict
# from src.annotation_types_old import
from src.input_parsers.interface import InputParser from src.input_parsers.interface import InputParser
from src.annotations import Annotation, MorphosyntacticAnnotation, NerAnnotation from src.annotations import Annotation, MorphosyntacticAnnotation, NerAnnotation
......
# from src.annotation_types_old import AnnotationTypes
from src.input_parsers.ccl import CCLInputParser from src.input_parsers.ccl import CCLInputParser
from tempfile import NamedTemporaryFile
from src.annotations import NerAnnotation, MorphosyntacticAnnotation from src.annotations import NerAnnotation, MorphosyntacticAnnotation
example_ccl = """<?xml version="1.0" encoding="UTF-8"?> example_ccl = """<?xml version="1.0" encoding="UTF-8"?>
......
# from src.annotation_types_old import AnnotationTypes
from src.input_parsers.wiktor_ner import WiktorNERInputParser from src.input_parsers.wiktor_ner import WiktorNERInputParser
from src.annotations import NerAnnotation, MorphosyntacticAnnotation from src.annotations import NerAnnotation, MorphosyntacticAnnotation
......
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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment