Rev 2 | Rev 104 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | szabot | 1 | #!/usr/bin/python |
2 | # -*- coding: utf-8 -*- |
||
3 | |||
4 | import re |
||
5 | |||
6 | num = [u"kew", |
||
7 | u"'aw", |
||
8 | u"mune", |
||
9 | u"pxey", |
||
10 | u"tsìng", |
||
11 | u"mrr", |
||
12 | u"pukap", |
||
13 | u"kinä"] |
||
14 | |||
15 | rem = [u"aw", |
||
16 | u"mun", |
||
17 | u"pey", |
||
18 | u"sìng", |
||
19 | u"mrr", |
||
20 | u"fu", |
||
21 | u"hin"] |
||
22 | |||
23 | base = [u"", |
||
24 | u"me", |
||
25 | u"pxe", |
||
26 | u"tsì", |
||
27 | u"mrr", |
||
28 | u"pu", |
||
29 | u"ki"] |
||
30 | |||
31 | |||
32 | numre = \ |
||
103 | szabot | 33 | u"^(a?)(?:(" + "|".join(base) + u")zazam??)?" + \ |
2 | szabot | 34 | u"(?:(" + "|".join(base) + u")vozam??)?" + \ |
35 | u"(?:(" + "|".join(base) + u")zam??)?" + \ |
||
36 | u"(?:(" + "|".join(base) + u")vo(?:l(?=a|))?)?" + \ |
||
37 | u"((?:" + "|".join(rem) + u")|" + \ |
||
103 | szabot | 38 | u"(?:" + "|".join(num) + u"))?(ve?)(a?)$" |
2 | szabot | 39 | numre = re.compile(numre) |
40 | |||
41 | def parse(numin): |
||
42 | if type(numin) != unicode: |
||
43 | return None |
||
44 | if numin == u"": |
||
45 | return None |
||
46 | numin = numin.replace(u"í",u"ì").replace(u"á",u"ä") |
||
47 | try: |
||
48 | mat = numre.match(numin).groups() |
||
49 | except: |
||
50 | return None |
||
51 | numout = 0 |
||
52 | numoct = 0 |
||
53 | try: |
||
103 | szabot | 54 | numout += rem.index(mat[5]) + 1 |
55 | numoct += rem.index(mat[5]) + 1 |
||
2 | szabot | 56 | except: |
57 | try: |
||
103 | szabot | 58 | numout += num.index(mat[5]) |
59 | numoct += num.index(mat[5]) |
||
2 | szabot | 60 | except: pass |
61 | try: |
||
103 | szabot | 62 | numout += (base.index(mat[4]) + 1) * 8 |
63 | numoct += (base.index(mat[4]) + 1) * 10 |
||
2 | szabot | 64 | except: pass |
65 | try: |
||
103 | szabot | 66 | numout += (base.index(mat[3]) + 1) * 8**2 |
67 | numoct += (base.index(mat[3]) + 1) * 10**2 |
||
2 | szabot | 68 | except: pass |
69 | try: |
||
103 | szabot | 70 | numout += (base.index(mat[2]) + 1) * 8**3 |
71 | numoct += (base.index(mat[2]) + 1) * 10**3 |
||
2 | szabot | 72 | except: pass |
73 | try: |
||
103 | szabot | 74 | numout += (base.index(mat[1]) + 1) * 8**4 |
75 | numoct += (base.index(mat[1]) + 1) * 10**4 |
||
2 | szabot | 76 | except: pass |
103 | szabot | 77 | retnum = unicode(numout) |
78 | if mat[6] != u"": |
||
79 | retnum += u"." |
||
80 | 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} |
||
81 | #return numout, numoct |
||
2 | szabot | 82 | |
83 | |||
84 | if __name__ == "__main__": |
||
85 | print parse(u"mrrvolaw") |