jetdumot/test.py
Tom Darboux 580d943698 Poc 1
2024-04-07 23:59:34 +02:00

22 lines
570 B
Python
Executable file

import xml.etree.ElementTree as ET
import json
tree = ET.parse('small.xml')
root = tree.getroot()
res = []
for wordEl in root:
alreadyAdd = False
for wordChild in wordEl:
if wordChild.tag == "lexeme" and not alreadyAdd:
word = wordEl.attrib.get("form")
wordType = wordChild.attrib.get("pos")
if word is not None and wordType is not None:
res.append({
"word": word,
"type": wordType
})
alreadyAdd = True
print(json.dumps(res))