Skip to content

Commit e7225d6

Browse files
committed
Add some doc
1 parent 757f0c4 commit e7225d6

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎stanza/utils/languages/spanish/__init__.py‎

Whitespace-only changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+

0 commit comments

Comments
 (0)