File tree Expand file tree Collapse file tree
stanza/utils/languages/spanish Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ """
2+ A simple, almost trivial script to read sentences from UD and mark any words of 'se' with a delimiter
3+
4+ Should be a useful input format for MLtwist to annotate the words
5+ """
6+
7+ from stanza .utils .conll import CoNLL
8+
9+ import sys
10+
11+ filename = sys .argv [1 ]
12+ doc = CoNLL .conll2doc (filename , reconstruct_text = True )
13+
14+ def process_se (doc ):
15+ for sentence in doc .sentences :
16+ for idx , token in enumerate (sentence .tokens ):
17+ if any (word .text == 'se' for word in token .words ):
18+ yield sentence , idx
19+
20+ for sentence , idx in process_se (doc ):
21+ token = sentence .tokens [idx ]
22+ # note that sentences have a start index somewhere in the middle of the doc,
23+ # not necessarily at 0
24+ start_char = token .start_char - sentence .tokens [0 ].start_char
25+ end_char = token .end_char - sentence .tokens [0 ].start_char
26+ text = sentence .text [:start_char ] + "---> " + token .text + " <---" + sentence .text [end_char :]
27+ print (text )
28+
You can’t perform that action at this time.
0 commit comments