Subversion Repositories navi

Rev

Rev 133 | Rev 135 | 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ä"]

numord = [u"kewve",
          u"'awve",
          u"muve",
          u"pxeyve",
          u"tsìve",
          u"mrrve",
          u"puve",
          u"kive"]

rem = [u"aw",
       u"mun",
       u"pey",
       u"sìng",
       u"mrr",
       u"fu",
       u"hin"]

remord = [u"awve",
       u"muve",
       u"peyve",
       u"sìve",
       u"mrrve",
       u"fuve",
       u"hive"]

base = [u"",
        u"me",
        u"pxe",
        u"tsì",
        u"mrr",
        u"pu",
        u"ki"]


numre = \
      u"^(a?)(?:(?:(" + "|".join(base) + u")zaza(?=m)(?:ve(?=$))?)?" + \
      u"(?:(" + "|".join(base) + u")voza(?=m)(?:ve(?=$))?)?" + \
      u"(?:(" + "|".join(base) + u")za(?=m)(?:ve(?=$))?)?" + \
      u"(?:(" + "|".join(base) + u")(?:vol|vo(?=a|$))(?:ve(?=$))?)?" + \
      u"(?:(" + "|".join(remord + rem) + u")))|" + \
      u"(?:(" + "|".join(numord + num) + u"))?(a?)$"
numre = re.compile(numre)

def parse(numin):
    if numin in (u"a", u"aa", u"ave", u"avea", u"ve", u"vea"):
        return None
    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[6])
            numoct += num.index(mat[6])
        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"."
    prefs = []
    posts = []
    if mat[0] != u"":
        prefs.append(mat[0])
    if mat[7] != u"":
        posts.append(mat[7])
    if "ve" in numin:
        posts.append("ve")
    return {"word": {"id": 0, "navi": retnum, "infix": u"", "type": u""}, "pref": [prefs], "post": [posts], "inf": [u"", u"", u""], "len": False, "dec": numout, "oct": numoct}
    #return numout, numoct


if __name__ == "__main__":
    print parse(u"mrrvolawvea")