Subversion Repositories navi

Rev

Rev 218 | Rev 220 | 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
 
23
num = [u"kew",
24
       u"'aw",
25
       u"mune",
26
       u"pxey",
27
       u"tsìng",
28
       u"mrr",
29
       u"pukap",
30
       u"kinä"]
31
 
32
numord = [u"kew",
33
          u"'aw",
34
          u"mu",
35
          u"pxey",
36
          u"tsì",
37
          u"mrr",
38
          u"pu",
39
          u"ki"]
40
 
41
rem = [u"aw",
42
       u"mun",
43
       u"pey",
44
       u"sìng",
45
       u"mrr",
46
       u"fu",
47
       u"hin"]
48
 
49
remord = [u"aw",
50
          u"mu",
51
          u"pey",
52
          u"sì",
53
          u"mrr",
54
          u"fu",
55
          u"hi"]
56
 
57
base = [u"",
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
205 muzer 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:]
149 szabot 78
    if numin[len(numin)-1] == u"a":
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]
84
 
85
    #base numbers
147 szabot 86
    for n in range(len(num)):
87
        if u"ve" in posts:
88
            if numin == numord[n]:
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:
96
            if numin == num[n]:
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
138 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)
218 szabot 109
            if numin[len(base[n]) + 4:].startswith(u"mrr") or numin[len(base[n]) + 4:].startswith(u"me"):
217 szabot 110
                numin = numin[len(base[n]) + 4:]
111
            else:
112
                numin = numin[len(base[n]) + 5:]
210 szabot 113
            notbase = True
138 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)
218 szabot 118
            if numin[len(base[n]) + 4:].startswith(u"mrr") or numin[len(base[n]) + 4:].startswith(u"me"):
217 szabot 119
                numin = numin[len(base[n]) + 4:]
120
            else:
121
                numin = numin[len(base[n]) + 5:]
210 szabot 122
            notbase = True
138 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)
218 szabot 127
            if numin[len(base[n]) + 4:].startswith(u"mrr") or numin[len(base[n]) + 4:].startswith(u"me"):
219 muzer 128
                print numin
217 szabot 129
                numin = numin[len(base[n]) + 2:]
130
            else:
131
                numin = numin[len(base[n]) + 3:]
210 szabot 132
            notbase = True
138 szabot 133
    for n in range(len(base)):
134
        if numin.startswith(base[n] + u"vol"):
135
            outoct += (n+1) * 10
136
            outdec += (n+1) * 8
137
            numin = numin[len(base[n]) + 3:]
210 szabot 138
            notbase = True
138 szabot 139
        if numin.startswith(base[n] + u"vo"):
140
            outoct += (n+1) * 10
141
            outdec += (n+1) * 8
142
            numin = numin[len(base[n]) + 2:]
210 szabot 143
            notbase = True
144
    if notbase:
145
        for n in range(len(rem)):
146
            if u"ve" in posts:
147
                if numin == remord[n]:
148
                    outoct += n + 1
149
                    outdec += n + 1
150
                    numin = u""
151
            else:
152
                if numin == rem[n]:
153
                    outoct += n + 1
154
                    outdec += n + 1
155
                    numin = u""
138 szabot 156
    if numin == u"":
157
        ret["word"]["navi"] = unicode(outdec) if not u"ve" in posts else unicode(outdec) + u"."
158
        ret["dec"] = outdec
159
        ret["oct"] = outoct
160
        return ret
161
    else:
141 szabot 162
        return None
138 szabot 163
 
164
if __name__ == "__main__":
176 muzer 165
    print parse(u"mevolawve")