Subversion Repositories navi

Rev

Rev 205 | Rev 218 | 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)
            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)
            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)
            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")