Rev 298 | 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 | |||
| 300 | muzer | 34 | NUMLEN = [u"hew", |
| 35 | u"aw", |
||
| 36 | u"mune", |
||
| 37 | u"pey", |
||
| 38 | u"sìng", |
||
| 39 | u"mrr", |
||
| 40 | u"fukap", |
||
| 41 | u"hinä"] |
||
| 42 | |||
| 246 | szabot | 43 | NUMORD = [u"kew", |
| 138 | szabot | 44 | u"'aw", |
| 45 | u"mu", |
||
| 46 | u"pxey", |
||
| 47 | u"tsì", |
||
| 48 | u"mrr", |
||
| 49 | u"pu", |
||
| 50 | u"ki"] |
||
| 51 | |||
| 300 | muzer | 52 | NUMORDLEN = [u"hew", |
| 53 | u"aw", |
||
| 54 | u"mu", |
||
| 55 | u"pey", |
||
| 56 | u"sì", |
||
| 57 | u"mrr", |
||
| 58 | u"fu", |
||
| 59 | u"hi"] |
||
| 60 | |||
| 246 | szabot | 61 | REM = [u"aw", |
| 138 | szabot | 62 | u"mun", |
| 63 | u"pey", |
||
| 64 | u"sìng", |
||
| 65 | u"mrr", |
||
| 66 | u"fu", |
||
| 67 | u"hin"] |
||
| 68 | |||
| 246 | szabot | 69 | REMORD = [u"aw", |
| 138 | szabot | 70 | u"mu", |
| 71 | u"pey", |
||
| 72 | u"sì", |
||
| 73 | u"mrr", |
||
| 74 | u"fu", |
||
| 75 | u"hi"] |
||
| 76 | |||
| 246 | szabot | 77 | BASE = [u"", |
| 138 | szabot | 78 | u"me", |
| 79 | u"pxe", |
||
| 80 | u"tsì", |
||
| 81 | u"mrr", |
||
| 82 | u"pu", |
||
| 83 | u"ki"] |
||
| 84 | |||
| 300 | muzer | 85 | BASELEN = [u"", |
| 86 | u"me", |
||
| 87 | u"pe", |
||
| 88 | u"sì", |
||
| 89 | u"mrr", |
||
| 90 | u"fu", |
||
| 91 | u"hi"] |
||
| 92 | |||
| 138 | szabot | 93 | def parse(numin): |
| 94 | if u"mm" in numin: |
||
| 95 | return None |
||
| 300 | muzer | 96 | if (numin == u"") or len(numin) == 1 or ((numin[0] == u"a" and numin[1] != "w") and (numin[len(numin) - 1] == u"a")): |
| 138 | szabot | 97 | return None |
| 98 | prefs = [] |
||
| 99 | posts = [] |
||
| 100 | outoct = 0 |
||
| 101 | outdec = 0 |
||
| 300 | muzer | 102 | frac = False |
| 103 | ret = {"word": {"id": 0, "navi": u"", "orig_navi": "", "infix": u"", "type": u""}, "pref": [prefs], "post": [posts], "inf": [u"", u"", u""], "len": False, "dec": outdec, "oct": outoct} |
||
| 104 | if numin[0] == u"a" and len(numin) > 1 and numin[1] != "w": |
||
| 298 | muzer | 105 | prefs.append((u"a", "a")) |
| 138 | szabot | 106 | numin = numin[1:] |
| 300 | muzer | 107 | elif numin[0:2] == "nì": |
| 108 | prefs.append(("nì", "nì")) |
||
| 109 | numin = numin[2:] |
||
| 246 | szabot | 110 | if numin[len(numin) - 1] == u"a": |
| 284 | muzer | 111 | posts.append((u"a", None)) |
| 149 | szabot | 112 | numin = numin[:-1] |
| 138 | szabot | 113 | if numin[-2:] == u"ve": |
| 284 | muzer | 114 | posts.append((u"ve", None)) |
| 138 | szabot | 115 | numin = numin[:-2] |
| 300 | muzer | 116 | if numin[-3:] == u"pxì": |
| 117 | posts.append((u"pxì", None)) |
||
| 118 | numin = numin[:-3] |
||
| 246 | szabot | 119 | |
| 300 | muzer | 120 | # Special fractions |
| 121 | if numin in ("mawl", "pan", "fan"): |
||
| 122 | outoct = 2 if numin == "mawl" else 3 |
||
| 123 | outdec = 2 if numin == "mawl" else 3 |
||
| 124 | ret["word"]["navi"] = "1/" + str(outdec) |
||
| 125 | ret["word"]["orig_navi"] = "mawl" if numin == "mawl" else "pan" |
||
| 126 | ret["dec"] = outdec |
||
| 127 | ret["oct"] = outoct |
||
| 128 | ret["len"] = True if numin == "fan" else False |
||
| 129 | return ret |
||
| 130 | |||
| 246 | szabot | 131 | #BASE numbers |
| 132 | for n in range(len(NUM)): |
||
| 284 | muzer | 133 | if (u"ve", None) in posts: |
| 246 | szabot | 134 | if numin == NUMORD[n]: |
| 147 | szabot | 135 | outoct = n |
| 136 | outdec = n |
||
| 283 | muzer | 137 | ret["word"]["navi"] = str(outdec) + u"." |
| 300 | muzer | 138 | ret["word"]["orig_navi"] = NUMORD[n] |
| 147 | szabot | 139 | ret["dec"] = outdec |
| 140 | ret["oct"] = outoct |
||
| 141 | return ret |
||
| 300 | muzer | 142 | if numin == NUMORDLEN[n]: |
| 143 | outoct = n |
||
| 144 | outdec = n |
||
| 145 | ret["word"]["navi"] = str(outdec) + u"." |
||
| 146 | ret["word"]["orig_navi"] = NUMORD[n] |
||
| 147 | ret["dec"] = outdec |
||
| 148 | ret["oct"] = outoct |
||
| 149 | ret["len"] = True |
||
| 150 | return ret |
||
| 151 | elif ("pxì", None) in posts and n > 3: |
||
| 152 | if numin == NUMORD[n]: |
||
| 153 | outoct = n |
||
| 154 | outdec = n |
||
| 155 | ret["word"]["navi"] = "1/" + str(outdec) |
||
| 156 | ret["word"]["orig_navi"] = NUMORD[n] |
||
| 157 | ret["dec"] = outdec |
||
| 158 | ret["oct"] = outoct |
||
| 159 | return ret |
||
| 160 | if numin == NUMORDLEN[n]: |
||
| 161 | outoct = n |
||
| 162 | outdec = n |
||
| 163 | ret["word"]["navi"] = "1/" + str(outdec) |
||
| 164 | ret["word"]["orig_navi"] = NUMORD[n] |
||
| 165 | ret["dec"] = outdec |
||
| 166 | ret["oct"] = outoct |
||
| 167 | ret["len"] = True |
||
| 168 | return ret |
||
| 147 | szabot | 169 | else: |
| 246 | szabot | 170 | if numin == NUM[n]: |
| 147 | szabot | 171 | outoct = n |
| 172 | outdec = n |
||
| 283 | muzer | 173 | ret["word"]["navi"] = str(outdec) |
| 300 | muzer | 174 | ret["word"]["orig_navi"] = NUM[n] |
| 147 | szabot | 175 | ret["dec"] = outdec |
| 176 | ret["oct"] = outoct |
||
| 177 | return ret |
||
| 300 | muzer | 178 | if numin == NUMLEN[n]: |
| 179 | outoct = n |
||
| 180 | outdec = n |
||
| 181 | ret["word"]["navi"] = str(outdec) |
||
| 182 | ret["word"]["orig_navi"] = NUM[n] |
||
| 183 | ret["dec"] = outdec |
||
| 184 | ret["oct"] = outoct |
||
| 185 | ret["len"] = True |
||
| 186 | return ret |
||
| 138 | szabot | 187 | #other numbers |
| 210 | szabot | 188 | notbase = False |
| 300 | muzer | 189 | orig_navi = "" |
| 246 | szabot | 190 | for n in range(len(BASE)): |
| 300 | muzer | 191 | if numin.startswith(BASE[n] + u"vozaza") or (not notbase and numin.startswith(BASELEN[n] + "vozaza")): |
| 192 | base = BASE[n] |
||
| 193 | if not numin.startswith(BASE[n]): |
||
| 194 | base = BASELEN[n] |
||
| 195 | ret["len"] = True |
||
| 253 | szabot | 196 | outoct += (n + 1) * (10 ** 5) |
| 197 | outdec += (n + 1) * (8 ** 5) |
||
| 300 | muzer | 198 | if numin[len(base) + 6:].startswith(u"mrr") or numin[len(base) + 6:].startswith(u"me") or numin[len(base) + 6:].startswith("mu") or not numin[len(base) + 6:].startswith("m"): |
| 199 | orig_navi += BASE[n] + "vozaza" |
||
| 200 | numin = numin[len(base) + 6:] |
||
| 253 | szabot | 201 | else: |
| 300 | muzer | 202 | orig_navi += BASE[n] + "vozazam" |
| 203 | numin = numin[len(base) + 7:] |
||
| 253 | szabot | 204 | notbase = True |
| 205 | for n in range(len(BASE)): |
||
| 300 | muzer | 206 | if numin.startswith(BASE[n] + u"zaza") or (not notbase and numin.startswith(BASELEN[n] + "zaza")): |
| 207 | base = BASE[n] |
||
| 208 | if not numin.startswith(BASE[n]): |
||
| 209 | base = BASELEN[n] |
||
| 210 | ret["len"] = True |
||
| 246 | szabot | 211 | outoct += (n + 1) * (10 ** 4) |
| 212 | outdec += (n + 1) * (8 ** 4) |
||
| 300 | muzer | 213 | if numin[len(base) + 4:].startswith(u"mrr") or numin[len(base) + 4:].startswith(u"me") or numin[len(base) + 4:].startswith("mu") or not numin[len(base) + 4:].startswith("m"): |
| 214 | orig_navi += BASE[n] + "zaza" |
||
| 215 | numin = numin[len(base) + 4:] |
||
| 217 | szabot | 216 | else: |
| 300 | muzer | 217 | orig_navi += BASE[n] + "zazam" |
| 218 | numin = numin[len(base) + 5:] |
||
| 210 | szabot | 219 | notbase = True |
| 246 | szabot | 220 | for n in range(len(BASE)): |
| 300 | muzer | 221 | if numin.startswith(BASE[n] + u"voza") or (not notbase and numin.startswith(BASELEN[n] + "voza")): |
| 222 | base = BASE[n] |
||
| 223 | if not numin.startswith(BASE[n]): |
||
| 224 | base = BASELEN[n] |
||
| 225 | ret["len"] = True |
||
| 246 | szabot | 226 | outoct += (n + 1) * (10 ** 3) |
| 227 | outdec += (n + 1) * (8 ** 3) |
||
| 300 | muzer | 228 | if numin[len(base) + 4:].startswith(u"mrr") or numin[len(base) + 4:].startswith(u"me") or numin[len(base) + 4:].startswith("mu") or not numin[len(base) + 4:].startswith("m"): |
| 229 | orig_navi += BASE[n] + "voza" |
||
| 230 | numin = numin[len(base) + 4:] |
||
| 217 | szabot | 231 | else: |
| 300 | muzer | 232 | orig_navi += BASE[n] + "vozam" |
| 233 | numin = numin[len(base) + 5:] |
||
| 210 | szabot | 234 | notbase = True |
| 246 | szabot | 235 | for n in range(len(BASE)): |
| 300 | muzer | 236 | if numin.startswith(BASE[n] + u"za") or (not notbase and numin.startswith(BASELEN[n] + "za")): |
| 237 | base = BASE[n] |
||
| 238 | if not numin.startswith(BASE[n]): |
||
| 239 | base = BASELEN[n] |
||
| 240 | ret["len"] = True |
||
| 246 | szabot | 241 | outoct += (n + 1) * (10 ** 2) |
| 242 | outdec += (n + 1) * (8 ** 2) |
||
| 300 | muzer | 243 | if numin[len(base) + 2:].startswith(u"mrr") or numin[len(base) + 2:].startswith(u"me") or numin[len(base) + 2:].startswith("mu") or not numin[len(base) + 2:].startswith("m"): |
| 244 | orig_navi += BASE[n] + "za" |
||
| 245 | numin = numin[len(base) + 2:] |
||
| 217 | szabot | 246 | else: |
| 300 | muzer | 247 | orig_navi += BASE[n] + "zam" |
| 248 | numin = numin[len(base) + 3:] |
||
| 210 | szabot | 249 | notbase = True |
| 246 | szabot | 250 | for n in range(len(BASE)): |
| 300 | muzer | 251 | if numin.startswith(BASE[n] + u"vol") or (not notbase and numin.startswith(BASELEN[n] + "vol")): |
| 252 | base = BASE[n] |
||
| 253 | if not numin.startswith(BASE[n]): |
||
| 254 | base = BASELEN[n] |
||
| 255 | ret["len"] = True |
||
| 246 | szabot | 256 | outoct += (n + 1) * 10 |
| 257 | outdec += (n + 1) * 8 |
||
| 300 | muzer | 258 | numin = numin[len(base) + 3:] |
| 210 | szabot | 259 | notbase = True |
| 300 | muzer | 260 | orig_navi += BASE[n] + "vol" |
| 261 | if numin.startswith(BASE[n] + u"vo") or (not notbase and numin.startswith(BASELEN[n] + "vo")): |
||
| 262 | base = BASE[n] |
||
| 263 | if not numin.startswith(BASE[n]): |
||
| 264 | base = BASELEN[n] |
||
| 265 | ret["len"] = True |
||
| 246 | szabot | 266 | outoct += (n + 1) * 10 |
| 267 | outdec += (n + 1) * 8 |
||
| 300 | muzer | 268 | numin = numin[len(base) + 2:] |
| 210 | szabot | 269 | notbase = True |
| 300 | muzer | 270 | orig_navi += BASE[n] + "vo" |
| 210 | szabot | 271 | if notbase: |
| 246 | szabot | 272 | for n in range(len(REM)): |
| 300 | muzer | 273 | if (u"ve", None) in posts or ("pxì", None) in posts: |
| 246 | szabot | 274 | if numin == REMORD[n]: |
| 300 | muzer | 275 | orig_navi += numin |
| 210 | szabot | 276 | outoct += n + 1 |
| 277 | outdec += n + 1 |
||
| 278 | numin = u"" |
||
| 279 | else: |
||
| 246 | szabot | 280 | if numin == REM[n]: |
| 300 | muzer | 281 | orig_navi += numin |
| 210 | szabot | 282 | outoct += n + 1 |
| 283 | outdec += n + 1 |
||
| 284 | numin = u"" |
||
| 138 | szabot | 285 | if numin == u"": |
| 300 | muzer | 286 | ret["word"]["navi"] = ("" if not ("pxì", None) in posts else "1/") + str(outdec) + ("" if not (u"ve", None) in posts else ".") |
| 287 | ret["word"]["orig_navi"] = orig_navi |
||
| 138 | szabot | 288 | ret["dec"] = outdec |
| 289 | ret["oct"] = outoct |
||
| 290 | return ret |
||
| 291 | else: |
||
| 141 | szabot | 292 | return None |
| 138 | szabot | 293 | |
| 294 | if __name__ == "__main__": |
||
| 283 | muzer | 295 | print(parse(u"mevolawve")) |