Rev 2 |
Rev 104 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
num = [u"kew",
u"'aw",
u"mune",
u"pxey",
u"tsìng",
u"mrr",
u"pukap",
u"kinä"]
rem = [u"aw",
u"mun",
u"pey",
u"sìng",
u"mrr",
u"fu",
u"hin"]
base = [u"",
u"me",
u"pxe",
u"tsì",
u"mrr",
u"pu",
u"ki"]
numre = \
u"^(a?)(?:(" + "|".join(base) + u")zazam??)?" + \
u"(?:(" + "|".join(base) + u")vozam??)?" + \
u"(?:(" + "|".join(base) + u")zam??)?" + \
u"(?:(" + "|".join(base) + u")vo(?:l(?=a|))?)?" + \
u"((?:" + "|".join(rem) + u")|" + \
u"(?:" + "|".join(num) + u"))?(ve?)(a?)$"
numre = re.compile(numre)
def parse(numin):
if type(numin) != unicode:
return None
if numin == u"":
return None
numin = numin.replace(u"í",u"ì").replace(u"á",u"ä")
try:
mat = numre.match(numin).groups()
except:
return None
numout = 0
numoct = 0
try:
numout += rem.index(mat[5]) + 1
numoct += rem.index(mat[5]) + 1
except:
try:
numout += num.index(mat[5])
numoct += num.index(mat[5])
except: pass
try:
numout += (base.index(mat[4]) + 1) * 8
numoct += (base.index(mat[4]) + 1) * 10
except: pass
try:
numout += (base.index(mat[3]) + 1) * 8**2
numoct += (base.index(mat[3]) + 1) * 10**2
except: pass
try:
numout += (base.index(mat[2]) + 1) * 8**3
numoct += (base.index(mat[2]) + 1) * 10**3
except: pass
try:
numout += (base.index(mat[1]) + 1) * 8**4
numoct += (base.index(mat[1]) + 1) * 10**4
except: pass
retnum = unicode(numout)
if mat[6] != u"":
retnum += u"."
return {"word": {"id": 0, "navi": retnum, "infix": u"", "type": u""}, "pref": [mat[0]], "post": [mat[6], mat[7]], "inf": [u"", u"", u""], "len": False, "dec": numout, "oct": numdec}
#return numout, numoct
if __name__ == "__main__":
print parse(u"mrrvolaw")