Vote count:
0
I am trying to create an XML structure from a list of strings, where each string has a list of scopes, referencing token indices. Using this data, I want to create an xml structure of sentences and scopes.
For example:
string = "Hello this is a very nice string"
scopes = [[2, 3, 4], [5, 6]]
From this I want to create the following structure:
<sentence>
Hello
<scope>this is a</scope>
<scope>very nice</scope>
sentence
</sentence>
I'm thinking something along the lines of this:
import xml.etree.ElementTree as et
def build_xml(string, scope)
root = et.Element('string')
root.text = string
for scope in scopes:
# wrap tokens at affected indices into scope tags
What's the best way to do this? Tokenizing the strings can be regarded as trivial.
asked 2 mins ago
Wrap ElementTree text in SubElement tags
Aucun commentaire:
Enregistrer un commentaire