-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupasarga_xml.py
34 lines (26 loc) · 883 Bytes
/
upasarga_xml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
''' Convert SL_preverbs.txt to SL_upasargas.xml
SL_preverbs.txt is searched for simple preverbs
XML structure is created and output to SL_upasargas.xml
Author: Karthik Madathil <kmadathil@gmail.com>
'''
import re
import lxml.etree as ET
# Regexp to match simple upasargas
lre=re.compile(r"^\s*(\w+)\s*=\s*\1\s*$")
with open("SL_preverbs.txt") as pf:
# Root element <forms>
fe=ET.Element("forms")
for pfl in pf:
m=lre.match(pfl)
if m:
up = m.group(1)
# Create XML Elements
# <f form=upasarga_name><upsrg /><stem=upasarga_name/></f>
f=ET.SubElement(fe,"f",form=up)
t=ET.SubElement(f,"upsrg")
s=ET.SubElement(f,"s",stem=up)
# Write out
with open("SL_upasargas.xml","w") as xo:
tree=ET.ElementTree(fe)
tree.write(xo,pretty_print=True)