1 the - определенный артикль
2 be v - быть
3 of - предлог родительного падежа
разбирает его и генерирует xml такого вида:
<meewords>
<words>
<word>
the
</word>
<translation>
определенный артикль
</translation>
</words>
<words>
<word>
be
</word>
<translation>
быть
</translation>
</words>
<words>
<word>
of
</word>
<translation>
предлог родительного падежа
</translation>
</words>
class Pars():
def run(self):
counter=0
for self.wrd in open(self.fal1):
self.s = self.wrd.split(' ')
del self.s[0]
if self.s[-1] == '\n':
del self.s[-1]
if self.s[1] == 'n' or self.s[1] == 'v':
del self.s[1]
self.s=' '.join(self.s)
self.i = self.s.find('-')
counter=counter+1
print 'processing words', counter
self.runXml()
class DomXml(Pars):
def __init__(self):
self.dom = minidom.Document()
self.a1 = self.dom.createElement("meewords")
self.dom.appendChild(self.a1)
def runXml(self):
self.b1 = self.dom.createElement("words")
self.a1.appendChild(self.b1)
self.c1 = self.dom.createElement("word")
self.c1.appendChild(self.dom.createTextNode(self.s[0:self.i]))
self.c2 = self.dom.createElement("translation")
self.c2.appendChild(self.dom.createTextNode(self.s[self.i + 1:]))
self.b1.appendChild(self.c1)
self.b1.appendChild(self.c2)
self.save()
class Start(DomXml):
def __init__(self, fal1, fal2):
DomXml.__init__(self)
self.fal1 = fal1
self.fal2 = fal2
self.run()
def save(self):
self.res = open(self.fal2, 'w')
self.res.writelines(self.dom.toprettyxml())
self.res.close()