Rev 104 | Go to most recent revision | Details | 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 = \ |
||
| 33 | u"^(?:(" + "|".join(base) + u")zazam??)?" + \ |
||
| 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")|" + \ |
||
| 38 | u"(?:" + "|".join(num) + u"))?$" |
||
| 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: |
||
| 54 | numout += rem.index(mat[4]) + 1 |
||
| 55 | numoct += rem.index(mat[4]) + 1 |
||
| 56 | except: |
||
| 57 | try: |
||
| 58 | numout += num.index(mat[4]) |
||
| 59 | numoct += num.index(mat[4]) |
||
| 60 | except: pass |
||
| 61 | try: |
||
| 62 | numout += (base.index(mat[3]) + 1) * 8 |
||
| 63 | numoct += (base.index(mat[3]) + 1) * 10 |
||
| 64 | except: pass |
||
| 65 | try: |
||
| 66 | numout += (base.index(mat[2]) + 1) * 8**2 |
||
| 67 | numoct += (base.index(mat[2]) + 1) * 10**2 |
||
| 68 | except: pass |
||
| 69 | try: |
||
| 70 | numout += (base.index(mat[1]) + 1) * 8**3 |
||
| 71 | numoct += (base.index(mat[1]) + 1) * 10**3 |
||
| 72 | except: pass |
||
| 73 | try: |
||
| 74 | numout += (base.index(mat[0]) + 1) * 8**4 |
||
| 75 | numoct += (base.index(mat[0]) + 1) * 10**4 |
||
| 76 | except: pass |
||
| 77 | return numout, numoct |
||
| 78 | |||
| 79 | |||
| 80 | if __name__ == "__main__": |
||
| 81 | print parse(u"mrrvolaw") |