Newer
Older
from src.input_parsers.interface import InputParser
from src.annotations import Annotation, MorphosyntacticAnnotation, NerAnnotation
class WiktorNERInputParser(InputParser):
def __init__(self) -> None:
super().__init__()
def parse(self, content: str) -> Tuple[str, List[Tuple[int, int, Annotation]]]:
"""Parse wiktorner file into text and annotations.
Annotations are returned as a dictionary with channel name as a key and list of tuples.
Args:
co z (str): Path to file containing CCL.
Returns:
Tuple[str, List[Tuple[int, int, Annotation]]]: Text and annotations.
"""
content_parsed = json.loads(content)
# Morphosyntactic annotations
if "tokens" in content_parsed:
for lexeme in token["lexemes"]:
if "disamb" in lexeme and lexeme["disamb"] == True:
annotations.append(
(
token_start,
token_end,
MorphosyntacticAnnotation(lexeme["mstag"]),
)
)
# NER annotations
if "entities" in content_parsed:
annotations.append(
(entity_start, entity_end, NerAnnotation(entity["type"]))
)
return text, annotations