Rev 253 | 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 | |
283 | muzer | 23 | from __future__ import print_function |
24 | |||
246 | szabot | 25 | NUM = [u"kew", |
138 | szabot | 26 | u"'aw", |
27 | u"mune", |
||
28 | u"pxey", |
||
29 | u"tsìng", |
||
30 | u"mrr", |
||
31 | u"pukap", |
||
32 | u"kinä"] |
||
33 | |||
246 | szabot | 34 | NUMORD = [u"kew", |
138 | szabot | 35 | u"'aw", |
36 | u"mu", |
||
37 | u"pxey", |
||
38 | u"tsì", |
||
39 | u"mrr", |
||
40 | u"pu", |
||
41 | u"ki"] |
||
42 | |||
246 | szabot | 43 | REM = [u"aw", |
138 | szabot | 44 | u"mun", |
45 | u"pey", |
||
46 | u"sìng", |
||
47 | u"mrr", |
||
48 | u"fu", |
||
49 | u"hin"] |
||
50 | |||
246 | szabot | 51 | REMORD = [u"aw", |
138 | szabot | 52 | u"mu", |
53 | u"pey", |
||
54 | u"sì", |
||
55 | u"mrr", |
||
56 | u"fu", |
||
57 | u"hi"] |
||
58 | |||
246 | szabot | 59 | BASE = [u"", |
138 | szabot | 60 | u"me", |
61 | u"pxe", |
||
62 | u"tsì", |
||
63 | u"mrr", |
||
64 | u"pu", |
||
65 | u"ki"] |
||
66 | |||
67 | def parse(numin): |
||
68 | if u"mm" in numin: |
||
69 | return None |
||
246 | szabot | 70 | if (numin == u"") or ((numin[0] == u"a") and (numin[len(numin) - 1] == u"a")): |
138 | szabot | 71 | return None |
72 | prefs = [] |
||
73 | posts = [] |
||
74 | outoct = 0 |
||
75 | outdec = 0 |
||
140 | szabot | 76 | 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 | 77 | if numin[0] == u"a": |
78 | prefs.append(u"a") |
||
79 | numin = numin[1:] |
||
246 | szabot | 80 | if numin[len(numin) - 1] == u"a": |
149 | szabot | 81 | posts.append(u"a") |
82 | numin = numin[:-1] |
||
138 | szabot | 83 | if numin[-2:] == u"ve": |
84 | posts.append(u"ve") |
||
85 | numin = numin[:-2] |
||
246 | szabot | 86 | |
87 | #BASE numbers |
||
88 | for n in range(len(NUM)): |
||
147 | szabot | 89 | if u"ve" in posts: |
246 | szabot | 90 | if numin == NUMORD[n]: |
147 | szabot | 91 | outoct = n |
92 | outdec = n |
||
283 | muzer | 93 | ret["word"]["navi"] = str(outdec) + u"." |
147 | szabot | 94 | ret["dec"] = outdec |
95 | ret["oct"] = outoct |
||
96 | return ret |
||
97 | else: |
||
246 | szabot | 98 | if numin == NUM[n]: |
147 | szabot | 99 | outoct = n |
100 | outdec = n |
||
283 | muzer | 101 | ret["word"]["navi"] = str(outdec) |
147 | szabot | 102 | ret["dec"] = outdec |
103 | ret["oct"] = outoct |
||
104 | return ret |
||
138 | szabot | 105 | #other numbers |
210 | szabot | 106 | notbase = False |
246 | szabot | 107 | for n in range(len(BASE)): |
253 | szabot | 108 | if numin.startswith(BASE[n] + u"vozazam"): |
109 | outoct += (n + 1) * (10 ** 5) |
||
110 | outdec += (n + 1) * (8 ** 5) |
||
111 | if numin[len(BASE[n]) + 6:].startswith(u"mrr") or numin[len(BASE[n]) + 6:].startswith(u"me"): |
||
112 | numin = numin[len(BASE[n]) + 6:] |
||
113 | else: |
||
114 | numin = numin[len(BASE[n]) + 7:] |
||
115 | notbase = True |
||
116 | for n in range(len(BASE)): |
||
246 | szabot | 117 | if numin.startswith(BASE[n] + u"zazam"): |
118 | outoct += (n + 1) * (10 ** 4) |
||
119 | outdec += (n + 1) * (8 ** 4) |
||
120 | if numin[len(BASE[n]) + 4:].startswith(u"mrr") or numin[len(BASE[n]) + 4:].startswith(u"me"): |
||
121 | numin = numin[len(BASE[n]) + 4:] |
||
217 | szabot | 122 | else: |
246 | szabot | 123 | numin = numin[len(BASE[n]) + 5:] |
210 | szabot | 124 | notbase = True |
246 | szabot | 125 | for n in range(len(BASE)): |
126 | if numin.startswith(BASE[n] + u"vozam"): |
||
127 | outoct += (n + 1) * (10 ** 3) |
||
128 | outdec += (n + 1) * (8 ** 3) |
||
129 | if numin[len(BASE[n]) + 4:].startswith(u"mrr") or numin[len(BASE[n]) + 4:].startswith(u"me"): |
||
130 | numin = numin[len(BASE[n]) + 4:] |
||
217 | szabot | 131 | else: |
246 | szabot | 132 | numin = numin[len(BASE[n]) + 5:] |
210 | szabot | 133 | notbase = True |
246 | szabot | 134 | for n in range(len(BASE)): |
135 | if numin.startswith(BASE[n] + u"zam"): |
||
136 | outoct += (n + 1) * (10 ** 2) |
||
137 | outdec += (n + 1) * (8 ** 2) |
||
138 | if numin[len(BASE[n]) + 2:].startswith(u"mrr") or numin[len(BASE[n]) + 2:].startswith(u"me"): |
||
139 | numin = numin[len(BASE[n]) + 2:] |
||
217 | szabot | 140 | else: |
246 | szabot | 141 | numin = numin[len(BASE[n]) + 3:] |
210 | szabot | 142 | notbase = True |
246 | szabot | 143 | for n in range(len(BASE)): |
144 | if numin.startswith(BASE[n] + u"vol"): |
||
145 | outoct += (n + 1) * 10 |
||
146 | outdec += (n + 1) * 8 |
||
147 | numin = numin[len(BASE[n]) + 3:] |
||
210 | szabot | 148 | notbase = True |
246 | szabot | 149 | if numin.startswith(BASE[n] + u"vo"): |
150 | outoct += (n + 1) * 10 |
||
151 | outdec += (n + 1) * 8 |
||
152 | numin = numin[len(BASE[n]) + 2:] |
||
210 | szabot | 153 | notbase = True |
154 | if notbase: |
||
246 | szabot | 155 | for n in range(len(REM)): |
210 | szabot | 156 | if u"ve" in posts: |
246 | szabot | 157 | if numin == REMORD[n]: |
210 | szabot | 158 | outoct += n + 1 |
159 | outdec += n + 1 |
||
160 | numin = u"" |
||
161 | else: |
||
246 | szabot | 162 | if numin == REM[n]: |
210 | szabot | 163 | outoct += n + 1 |
164 | outdec += n + 1 |
||
165 | numin = u"" |
||
138 | szabot | 166 | if numin == u"": |
283 | muzer | 167 | ret["word"]["navi"] = str(outdec) if not u"ve" in posts else str(outdec) + u"." |
138 | szabot | 168 | ret["dec"] = outdec |
169 | ret["oct"] = outoct |
||
170 | return ret |
||
171 | else: |
||
141 | szabot | 172 | return None |
138 | szabot | 173 | |
174 | if __name__ == "__main__": |
||
283 | muzer | 175 | print(parse(u"mevolawve")) |