Subversion Repositories navi

Rev

Rev 205 | Rev 218 | 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)
109
            numin = numin[len(base[n]) + 5:]
210 szabot 110
            notbase = True
138 szabot 111
    for n in range(len(base)):
112
        if numin.startswith(base[n] + u"vozam"):
113
            outoct += (n+1) * (10**3)
114
            outdec += (n+1) * (8**3)
115
            numin = numin[len(base[n]) + 5:]
210 szabot 116
            notbase = True
138 szabot 117
    for n in range(len(base)):
118
        if numin.startswith(base[n] + u"zam"):
119
            outoct += (n+1) * (10**2)
120
            outdec += (n+1) * (8**2)
121
            numin = numin[len(base[n]) + 3:]
210 szabot 122
            notbase = True
138 szabot 123
    for n in range(len(base)):
124
        if numin.startswith(base[n] + u"vol"):
125
            outoct += (n+1) * 10
126
            outdec += (n+1) * 8
127
            numin = numin[len(base[n]) + 3:]
210 szabot 128
            notbase = True
138 szabot 129
        if numin.startswith(base[n] + u"vo"):
130
            outoct += (n+1) * 10
131
            outdec += (n+1) * 8
132
            numin = numin[len(base[n]) + 2:]
210 szabot 133
            notbase = True
134
    if notbase:
135
        for n in range(len(rem)):
136
            if u"ve" in posts:
137
                if numin == remord[n]:
138
                    outoct += n + 1
139
                    outdec += n + 1
140
                    numin = u""
141
            else:
142
                if numin == rem[n]:
143
                    outoct += n + 1
144
                    outdec += n + 1
145
                    numin = u""
138 szabot 146
    if numin == u"":
147
        ret["word"]["navi"] = unicode(outdec) if not u"ve" in posts else unicode(outdec) + u"."
148
        ret["dec"] = outdec
149
        ret["oct"] = outoct
150
        return ret
151
    else:
141 szabot 152
        return None
138 szabot 153
 
154
if __name__ == "__main__":
176 muzer 155
    print parse(u"mevolawve")