Subversion Repositories navi

Rev

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

Rev Author Line No. Line
138 szabot 1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
176 muzer 3
#    This file is part of Tsim Apiak.
4
#
5
#    Tsim Apiak is free software: you can redistribute it and/or modify
6
#    it under the terms of the GNU General Public Licence as published by
7
#    the Free Software Foundation, either version 3 of the Licence, or
8
#    (at your option) any later version. 
9
# 
10
#    In addition to this, you must also comply with clause 4 of the
11
#    Apache Licence, version 2.0, concerning attribution. Where there
12
#    is a contradiction between the two licences, the GPL
13
#    takes preference.
14
#
186 szabot 15
#    Tsim Apiak is distributed in the hope that it will be useful,
176 muzer 16
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
#    GNU General Public License for more details.
19
#
20
#    You should have received a copy of the GNU General Public License
21
#    along with Tsim Apiak.  If not, see <http://www.gnu.org/licenses/>.
138 szabot 22
 
246 szabot 23
NUM = [u"kew",
138 szabot 24
       u"'aw",
25
       u"mune",
26
       u"pxey",
27
       u"tsìng",
28
       u"mrr",
29
       u"pukap",
30
       u"kinä"]
31
 
246 szabot 32
NUMORD = [u"kew",
138 szabot 33
          u"'aw",
34
          u"mu",
35
          u"pxey",
36
          u"tsì",
37
          u"mrr",
38
          u"pu",
39
          u"ki"]
40
 
246 szabot 41
REM = [u"aw",
138 szabot 42
       u"mun",
43
       u"pey",
44
       u"sìng",
45
       u"mrr",
46
       u"fu",
47
       u"hin"]
48
 
246 szabot 49
REMORD = [u"aw",
138 szabot 50
          u"mu",
51
          u"pey",
52
          u"sì",
53
          u"mrr",
54
          u"fu",
55
          u"hi"]
56
 
246 szabot 57
BASE = [u"",
138 szabot 58
        u"me",
59
        u"pxe",
60
        u"tsì",
61
        u"mrr",
62
        u"pu",
63
        u"ki"]
64
 
65
def parse(numin):
66
    if u"mm" in numin:
67
        return None
246 szabot 68
    if (numin == u"") or ((numin[0] == u"a") and (numin[len(numin) - 1] == u"a")):
138 szabot 69
        return None
70
    prefs = []
71
    posts = []
72
    outoct = 0
73
    outdec = 0
140 szabot 74
    ret = {"word": {"id": 0, "navi": u"", "infix": u"", "type": u""}, "pref": [prefs], "post": [posts], "inf": [u"", u"", u""], "len": False, "dec": outdec, "oct": outoct}
138 szabot 75
    if numin[0] == u"a":
76
        prefs.append(u"a")
77
        numin = numin[1:]
246 szabot 78
    if numin[len(numin) - 1] == u"a":
149 szabot 79
        posts.append(u"a")
80
        numin = numin[:-1]
138 szabot 81
    if numin[-2:] == u"ve":
82
        posts.append(u"ve")
83
        numin = numin[:-2]
246 szabot 84
 
85
    #BASE numbers
86
    for n in range(len(NUM)):
147 szabot 87
        if u"ve" in posts:
246 szabot 88
            if numin == NUMORD[n]:
147 szabot 89
                outoct = n
90
                outdec = n
91
                ret["word"]["navi"] = unicode(outdec) + u"."
92
                ret["dec"] = outdec
93
                ret["oct"] = outoct
94
                return ret
95
        else:
246 szabot 96
            if numin == NUM[n]:
147 szabot 97
                outoct = n
98
                outdec = n
99
                ret["word"]["navi"] = unicode(outdec)
100
                ret["dec"] = outdec
101
                ret["oct"] = outoct
102
                return ret
138 szabot 103
    #other numbers
210 szabot 104
    notbase = False
246 szabot 105
    for n in range(len(BASE)):
106
        if numin.startswith(BASE[n] + u"zazam"):
107
            outoct += (n + 1) * (10 ** 4)
108
            outdec += (n + 1) * (8 ** 4)
109
            if numin[len(BASE[n]) + 4:].startswith(u"mrr") or numin[len(BASE[n]) + 4:].startswith(u"me"):
110
                numin = numin[len(BASE[n]) + 4:]
217 szabot 111
            else:
246 szabot 112
                numin = numin[len(BASE[n]) + 5:]
210 szabot 113
            notbase = True
246 szabot 114
    for n in range(len(BASE)):
115
        if numin.startswith(BASE[n] + u"vozam"):
116
            outoct += (n + 1) * (10 ** 3)
117
            outdec += (n + 1) * (8 ** 3)
118
            if numin[len(BASE[n]) + 4:].startswith(u"mrr") or numin[len(BASE[n]) + 4:].startswith(u"me"):
119
                numin = numin[len(BASE[n]) + 4:]
217 szabot 120
            else:
246 szabot 121
                numin = numin[len(BASE[n]) + 5:]
210 szabot 122
            notbase = True
246 szabot 123
    for n in range(len(BASE)):
124
        if numin.startswith(BASE[n] + u"zam"):
125
            outoct += (n + 1) * (10 ** 2)
126
            outdec += (n + 1) * (8 ** 2)
127
            if numin[len(BASE[n]) + 2:].startswith(u"mrr") or numin[len(BASE[n]) + 2:].startswith(u"me"):
128
                numin = numin[len(BASE[n]) + 2:]
217 szabot 129
            else:
246 szabot 130
                numin = numin[len(BASE[n]) + 3:]
210 szabot 131
            notbase = True
246 szabot 132
    for n in range(len(BASE)):
133
        if numin.startswith(BASE[n] + u"vol"):
134
            outoct += (n + 1) * 10
135
            outdec += (n + 1) * 8
136
            numin = numin[len(BASE[n]) + 3:]
210 szabot 137
            notbase = True
246 szabot 138
        if numin.startswith(BASE[n] + u"vo"):
139
            outoct += (n + 1) * 10
140
            outdec += (n + 1) * 8
141
            numin = numin[len(BASE[n]) + 2:]
210 szabot 142
            notbase = True
143
    if notbase:
246 szabot 144
        for n in range(len(REM)):
210 szabot 145
            if u"ve" in posts:
246 szabot 146
                if numin == REMORD[n]:
210 szabot 147
                    outoct += n + 1
148
                    outdec += n + 1
149
                    numin = u""
150
            else:
246 szabot 151
                if numin == REM[n]:
210 szabot 152
                    outoct += n + 1
153
                    outdec += n + 1
154
                    numin = u""
138 szabot 155
    if numin == u"":
156
        ret["word"]["navi"] = unicode(outdec) if not u"ve" in posts else unicode(outdec) + u"."
157
        ret["dec"] = outdec
158
        ret["oct"] = outoct
159
        return ret
160
    else:
141 szabot 161
        return None
138 szabot 162
 
163
if __name__ == "__main__":
176 muzer 164
    print parse(u"mevolawve")