Subversion Repositories navi

Rev

Rev 246 | Rev 284 | 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)):
253 szabot 106
        if numin.startswith(BASE[n] + u"vozazam"):
107
            outoct += (n + 1) * (10 ** 5)
108
            outdec += (n + 1) * (8 ** 5)
109
            if numin[len(BASE[n]) + 6:].startswith(u"mrr") or numin[len(BASE[n]) + 6:].startswith(u"me"):
110
                numin = numin[len(BASE[n]) + 6:]
111
            else:
112
                numin = numin[len(BASE[n]) + 7:]
113
            notbase = True
114
    for n in range(len(BASE)):
246 szabot 115
        if numin.startswith(BASE[n] + u"zazam"):
116
            outoct += (n + 1) * (10 ** 4)
117
            outdec += (n + 1) * (8 ** 4)
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"vozam"):
125
            outoct += (n + 1) * (10 ** 3)
126
            outdec += (n + 1) * (8 ** 3)
127
            if numin[len(BASE[n]) + 4:].startswith(u"mrr") or numin[len(BASE[n]) + 4:].startswith(u"me"):
128
                numin = numin[len(BASE[n]) + 4:]
217 szabot 129
            else:
246 szabot 130
                numin = numin[len(BASE[n]) + 5:]
210 szabot 131
            notbase = True
246 szabot 132
    for n in range(len(BASE)):
133
        if numin.startswith(BASE[n] + u"zam"):
134
            outoct += (n + 1) * (10 ** 2)
135
            outdec += (n + 1) * (8 ** 2)
136
            if numin[len(BASE[n]) + 2:].startswith(u"mrr") or numin[len(BASE[n]) + 2:].startswith(u"me"):
137
                numin = numin[len(BASE[n]) + 2:]
217 szabot 138
            else:
246 szabot 139
                numin = numin[len(BASE[n]) + 3:]
210 szabot 140
            notbase = True
246 szabot 141
    for n in range(len(BASE)):
142
        if numin.startswith(BASE[n] + u"vol"):
143
            outoct += (n + 1) * 10
144
            outdec += (n + 1) * 8
145
            numin = numin[len(BASE[n]) + 3:]
210 szabot 146
            notbase = True
246 szabot 147
        if numin.startswith(BASE[n] + u"vo"):
148
            outoct += (n + 1) * 10
149
            outdec += (n + 1) * 8
150
            numin = numin[len(BASE[n]) + 2:]
210 szabot 151
            notbase = True
152
    if notbase:
246 szabot 153
        for n in range(len(REM)):
210 szabot 154
            if u"ve" in posts:
246 szabot 155
                if numin == REMORD[n]:
210 szabot 156
                    outoct += n + 1
157
                    outdec += n + 1
158
                    numin = u""
159
            else:
246 szabot 160
                if numin == REM[n]:
210 szabot 161
                    outoct += n + 1
162
                    outdec += n + 1
163
                    numin = u""
138 szabot 164
    if numin == u"":
165
        ret["word"]["navi"] = unicode(outdec) if not u"ve" in posts else unicode(outdec) + u"."
166
        ret["dec"] = outdec
167
        ret["oct"] = outoct
168
        return ret
169
    else:
141 szabot 170
        return None
138 szabot 171
 
172
if __name__ == "__main__":
176 muzer 173
    print parse(u"mevolawve")