Subversion Repositories navi

Rev

Rev 220 | Rev 253 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/usr/bin/python
# -*- coding: utf-8 -*-
#    This file is part of Tsim Apiak.
#
#    Tsim Apiak is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public Licence as published by
#    the Free Software Foundation, either version 3 of the Licence, or
#    (at your option) any later version.
#
#    In addition to this, you must also comply with clause 4 of the
#    Apache Licence, version 2.0, concerning attribution. Where there
#    is a contradiction between the two licences, the GPL
#    takes preference.
#
#    Tsim Apiak is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Tsim Apiak.  If not, see <http://www.gnu.org/licenses/>.

NUM = [u"kew",
       u"'aw",
       u"mune",
       u"pxey",
       u"tsìng",
       u"mrr",
       u"pukap",
       u"kinä"]

NUMORD = [u"kew",
          u"'aw",
          u"mu",
          u"pxey",
          u"tsì",
          u"mrr",
          u"pu",
          u"ki"]

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

REMORD = [u"aw",
          u"mu",
          u"pey",
          u"sì",
          u"mrr",
          u"fu",
          u"hi"]

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

def parse(numin):
    if u"mm" in numin:
        return None
    if (numin == u"") or ((numin[0] == u"a") and (numin[len(numin) - 1] == u"a")):
        return None
    prefs = []
    posts = []
    outoct = 0
    outdec = 0
    ret = {"word": {"id": 0, "navi": u"", "infix": u"", "type": u""}, "pref": [prefs], "post": [posts], "inf": [u"", u"", u""], "len": False, "dec": outdec, "oct": outoct}
    if numin[0] == u"a":
        prefs.append(u"a")
        numin = numin[1:]
    if numin[len(numin) - 1] == u"a":
        posts.append(u"a")
        numin = numin[:-1]
    if numin[-2:] == u"ve":
        posts.append(u"ve")
        numin = numin[:-2]

    #BASE numbers
    for n in range(len(NUM)):
        if u"ve" in posts:
            if numin == NUMORD[n]:
                outoct = n
                outdec = n
                ret["word"]["navi"] = unicode(outdec) + u"."
                ret["dec"] = outdec
                ret["oct"] = outoct
                return ret
        else:
            if numin == NUM[n]:
                outoct = n
                outdec = n
                ret["word"]["navi"] = unicode(outdec)
                ret["dec"] = outdec
                ret["oct"] = outoct
                return ret
    #other numbers
    notbase = False
    for n in range(len(BASE)):
        if numin.startswith(BASE[n] + u"zazam"):
            outoct += (n + 1) * (10 ** 4)
            outdec += (n + 1) * (8 ** 4)
            if numin[len(BASE[n]) + 4:].startswith(u"mrr") or numin[len(BASE[n]) + 4:].startswith(u"me"):
                numin = numin[len(BASE[n]) + 4:]
            else:
                numin = numin[len(BASE[n]) + 5:]
            notbase = True
    for n in range(len(BASE)):
        if numin.startswith(BASE[n] + u"vozam"):
            outoct += (n + 1) * (10 ** 3)
            outdec += (n + 1) * (8 ** 3)
            if numin[len(BASE[n]) + 4:].startswith(u"mrr") or numin[len(BASE[n]) + 4:].startswith(u"me"):
                numin = numin[len(BASE[n]) + 4:]
            else:
                numin = numin[len(BASE[n]) + 5:]
            notbase = True
    for n in range(len(BASE)):
        if numin.startswith(BASE[n] + u"zam"):
            outoct += (n + 1) * (10 ** 2)
            outdec += (n + 1) * (8 ** 2)
            if numin[len(BASE[n]) + 2:].startswith(u"mrr") or numin[len(BASE[n]) + 2:].startswith(u"me"):
                numin = numin[len(BASE[n]) + 2:]
            else:
                numin = numin[len(BASE[n]) + 3:]
            notbase = True
    for n in range(len(BASE)):
        if numin.startswith(BASE[n] + u"vol"):
            outoct += (n + 1) * 10
            outdec += (n + 1) * 8
            numin = numin[len(BASE[n]) + 3:]
            notbase = True
        if numin.startswith(BASE[n] + u"vo"):
            outoct += (n + 1) * 10
            outdec += (n + 1) * 8
            numin = numin[len(BASE[n]) + 2:]
            notbase = True
    if notbase:
        for n in range(len(REM)):
            if u"ve" in posts:
                if numin == REMORD[n]:
                    outoct += n + 1
                    outdec += n + 1
                    numin = u""
            else:
                if numin == REM[n]:
                    outoct += n + 1
                    outdec += n + 1
                    numin = u""
    if numin == u"":
        ret["word"]["navi"] = unicode(outdec) if not u"ve" in posts else unicode(outdec) + u"."
        ret["dec"] = outdec
        ret["oct"] = outoct
        return ret
    else:
        return None

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