Newer
Older
from src.annotations import Annotation, MorphosyntacticAnnotation, NerAnnotation
from src.input_parsers.interface import InputParser
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Parser for WiktorNER files.
Example WiktorNER file:
{
"filename": "greeting-5b1401",
"text": "Hello Tom!",
"tokens": [
{
"index": 1,
"position": [0,5],
"orth": "Hello",
"lex": [
{
"lemma": "hello",
"mstag": "interj"
}
]
},
{
"index": 2,
"position": [6,9],
"orth": "Tom",
"lex": [
{
"lemma": "Tom",
"mstag": "noun"
}
]
},
{
"index": 3,
"position": [9,10],
"orth": "!",
"lex": [
{
"lemma": "!",
"mstag": "interp"
}
]
}
],
"entities": [
{
"text": "Tom",
"type": "nam_prs_human",
"tokens": [2],
"positions": [6,9]
}
]
}
"""
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.
annotations = []
# Morphosyntactic annotations
if token.lexemes:
for lexeme in token.lexemes:
if lexeme.disamb and lexeme.disamb is True:
if lexeme.pos:
if lexeme.lemma:
lemma = lexeme.lemma
else:
lemma = None
annotations.append(
(
token.start,
token.stop,
MorphosyntacticAnnotation(
lexeme.pos, lemma
),
if 'ner' in content.get_span_types():
if entity.type:
annotations.append(
(entity.start, entity.stop, NerAnnotation(entity.type))
)