Subversion Repositories navi

Rev

Rev 298 | 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/>.

from __future__ import print_function

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

NUMLEN = [u"hew",
       u"aw",
       u"mune",
       u"pey",
       u"sìng",
       u"mrr",
       u"fukap",
       u"hinä"]

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

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

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"]

BASELEN = [u"",
        u"me",
        u"pe",
        u"sì",
        u"mrr",
        u"fu",
        u"hi"]

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

    # Special fractions
    if numin in ("mawl", "pan", "fan"):
        outoct = 2 if numin == "mawl" else 3
        outdec = 2 if numin == "mawl" else 3
        ret["word"]["navi"] = "1/" + str(outdec)
        ret["word"]["orig_navi"] = "mawl" if numin == "mawl" else "pan"
        ret["dec"] = outdec
        ret["oct"] = outoct
        ret["len"] = True if numin == "fan" else False
        return ret

    #BASE numbers
    for n in range(len(NUM)):
        if (u"ve", None) in posts:
            if numin == NUMORD[n]:
                outoct = n
                outdec = n
                ret["word"]["navi"] = str(outdec) + u"."
                ret["word"]["orig_navi"] = NUMORD[n]
                ret["dec"] = outdec
                ret["oct"] = outoct
                return ret
            if numin == NUMORDLEN[n]:
                outoct = n
                outdec = n
                ret["word"]["navi"] = str(outdec) + u"."
                ret["word"]["orig_navi"] = NUMORD[n]
                ret["dec"] = outdec
                ret["oct"] = outoct
                ret["len"] = True
                return ret
        elif ("pxì", None) in posts and n > 3:
            if numin == NUMORD[n]:
                outoct = n
                outdec = n
                ret["word"]["navi"] = "1/" + str(outdec)
                ret["word"]["orig_navi"] = NUMORD[n]
                ret["dec"] = outdec
                ret["oct"] = outoct
                return ret
            if numin == NUMORDLEN[n]:
                outoct = n
                outdec = n
                ret["word"]["navi"] = "1/" + str(outdec)
                ret["word"]["orig_navi"] = NUMORD[n]
                ret["dec"] = outdec
                ret["oct"] = outoct
                ret["len"] = True
                return ret
        else:
            if numin == NUM[n]:
                outoct = n
                outdec = n
                ret["word"]["navi"] = str(outdec)
                ret["word"]["orig_navi"] = NUM[n]
                ret["dec"] = outdec
                ret["oct"] = outoct
                return ret
            if numin == NUMLEN[n]:
                outoct = n
                outdec = n
                ret["word"]["navi"] = str(outdec)
                ret["word"]["orig_navi"] = NUM[n]
                ret["dec"] = outdec
                ret["oct"] = outoct
                ret["len"] = True
                return ret
    #other numbers
    notbase = False
    orig_navi = ""
    for n in range(len(BASE)):
        if numin.startswith(BASE[n] + u"vozaza") or (not notbase and numin.startswith(BASELEN[n] + "vozaza")):
            base = BASE[n]
            if not numin.startswith(BASE[n]):
                base = BASELEN[n]
                ret["len"] = True
            outoct += (n + 1) * (10 ** 5)
            outdec += (n + 1) * (8 ** 5)
            if numin[len(base) + 6:].startswith(u"mrr") or numin[len(base) + 6:].startswith(u"me") or numin[len(base) + 6:].startswith("mu") or not numin[len(base) + 6:].startswith("m"):
                orig_navi += BASE[n] + "vozaza"
                numin = numin[len(base) + 6:]
            else:
                orig_navi += BASE[n] + "vozazam"
                numin = numin[len(base) + 7:]
            notbase = True
    for n in range(len(BASE)):
        if numin.startswith(BASE[n] + u"zaza") or (not notbase and numin.startswith(BASELEN[n] + "zaza")):
            base = BASE[n]
            if not numin.startswith(BASE[n]):
                base = BASELEN[n]
                ret["len"] = True
            outoct += (n + 1) * (10 ** 4)
            outdec += (n + 1) * (8 ** 4)
            if numin[len(base) + 4:].startswith(u"mrr") or numin[len(base) + 4:].startswith(u"me") or numin[len(base) + 4:].startswith("mu") or not numin[len(base) + 4:].startswith("m"):
                orig_navi += BASE[n] + "zaza"
                numin = numin[len(base) + 4:]
            else:
                orig_navi += BASE[n] + "zazam"
                numin = numin[len(base) + 5:]
            notbase = True
    for n in range(len(BASE)):
        if numin.startswith(BASE[n] + u"voza") or (not notbase and numin.startswith(BASELEN[n] + "voza")):
            base = BASE[n]
            if not numin.startswith(BASE[n]):
                base = BASELEN[n]
                ret["len"] = True
            outoct += (n + 1) * (10 ** 3)
            outdec += (n + 1) * (8 ** 3)
            if numin[len(base) + 4:].startswith(u"mrr") or numin[len(base) + 4:].startswith(u"me") or numin[len(base) + 4:].startswith("mu") or not numin[len(base) + 4:].startswith("m"):
                orig_navi += BASE[n] + "voza"
                numin = numin[len(base) + 4:]
            else:
                orig_navi += BASE[n] + "vozam"
                numin = numin[len(base) + 5:]
            notbase = True
    for n in range(len(BASE)):
        if numin.startswith(BASE[n] + u"za") or (not notbase and numin.startswith(BASELEN[n] + "za")):
            base = BASE[n]
            if not numin.startswith(BASE[n]):
                base = BASELEN[n]
                ret["len"] = True
            outoct += (n + 1) * (10 ** 2)
            outdec += (n + 1) * (8 ** 2)
            if numin[len(base) + 2:].startswith(u"mrr") or numin[len(base) + 2:].startswith(u"me") or numin[len(base) + 2:].startswith("mu") or not numin[len(base) + 2:].startswith("m"):
                orig_navi += BASE[n] + "za"
                numin = numin[len(base) + 2:]
            else:
                orig_navi += BASE[n] + "zam"
                numin = numin[len(base) + 3:]
            notbase = True
    for n in range(len(BASE)):
        if numin.startswith(BASE[n] + u"vol") or (not notbase and numin.startswith(BASELEN[n] + "vol")):
            base = BASE[n]
            if not numin.startswith(BASE[n]):
                base = BASELEN[n]
                ret["len"] = True
            outoct += (n + 1) * 10
            outdec += (n + 1) * 8
            numin = numin[len(base) + 3:]
            notbase = True
            orig_navi += BASE[n] + "vol"
        if numin.startswith(BASE[n] + u"vo") or (not notbase and numin.startswith(BASELEN[n] + "vo")):
            base = BASE[n]
            if not numin.startswith(BASE[n]):
                base = BASELEN[n]
                ret["len"] = True
            outoct += (n + 1) * 10
            outdec += (n + 1) * 8
            numin = numin[len(base) + 2:]
            notbase = True
            orig_navi += BASE[n] + "vo"
    if notbase:
        for n in range(len(REM)):
            if (u"ve", None) in posts or ("pxì", None) in posts:
                if numin == REMORD[n]:
                    orig_navi += numin
                    outoct += n + 1
                    outdec += n + 1
                    numin = u""
            else:
                if numin == REM[n]:
                    orig_navi += numin
                    outoct += n + 1
                    outdec += n + 1
                    numin = u""
    if numin == u"":
        ret["word"]["navi"] = ("" if not ("pxì", None) in posts else "1/") + str(outdec) + ("" if not (u"ve", None) in posts else ".")
        ret["word"]["orig_navi"] = orig_navi
        ret["dec"] = outdec
        ret["oct"] = outoct
        return ret
    else:
        return None

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