Skip to content
Snippets Groups Projects
Commit 3e1224b8 authored by Alice Brenon's avatar Alice Brenon
Browse files

Don't forget to escape XML characters in output

parent 37a652cc
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ import os
import os.path
import stanza
import sys
from xml.sax.saxutils import escape, quoteattr
class Annotator:
def __init__(self, source, target):
......@@ -45,10 +46,10 @@ class Annotator:
print('\t</s>', file=target)
def encode_token(self, token, target):
form = token.text
lemma = '+'.join(map(lambda w: w.lemma, token.words))
upos = '+'.join(map(lambda w: w.upos, token.words))
print(f'\t\t<w lemma="{lemma}" pos="{upos}">{form}</w>', file=target)
form = escape(token.text)
lemma = quoteattr('+'.join(map(lambda w: w.lemma, token.words)))
upos = quoteattr('+'.join(map(lambda w: w.upos, token.words)))
print(f'\t\t<w lemma={lemma} pos={upos}>{form}</w>', file=target)
if __name__ == '__main__':
Annotator(sys.argv[1], sys.argv[2]).run()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment