Rev 55 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 56 | szabot | 1 | #!/usr/bin/python |
| 2 | # -*- coding: utf-8 -*- |
||
| 3 | |||
| 4 | import re |
||
| 65 | szabot | 5 | #import dbconnector |
| 56 | szabot | 6 | |
| 65 | szabot | 7 | wordlist = dbconnector.getnavilist() |
| 8 | |||
| 9 | #wordlist = [{"id": 1, "navi": u"si", "infix": u"s<1><2><3>i", "type": u"v."}, |
||
| 10 | #{"id": 2, "navi": u"wou", "infix": u"w<1><2>o<3>u", "type": u"v."}, |
||
| 11 | #{"id": 3, "navi": u"kame", "infix": u"k<1><2>am<3>e", "type": u"v."}, |
||
| 12 | #{"id": 4, "navi": u"tìng", "infix": u"t<1><2><3>ìng", "type": u"v."}, |
||
| 13 | #{"id": 5, "navi": u"yerik", "infix": u"yerik", "type": u"n."}, |
||
| 14 | #{"id": 6, "navi": u"nari", "infix": u"nari", "type": u"n."}] |
||
| 15 | |||
| 16 | infixes1 = [u"awn", u"eyk", u"us", u"äp", u""] |
||
| 17 | infixes2 = [u"ìyev", u"iyev", u"ìmìy", u"arm", u"asy", u"ilv", u"ìmv", u"imv", u"ìrm", u"irv", u"ìsy", u"aly", u"ary", u"ìly", u"ìry", u"ìlm", u"alm", u"am", u"ay", u"er", u"ìm", u"iv", u"ìy", u"ol", u""] |
||
| 18 | infixes3 = [u"äng", u"ats", u"eiy", u"ei", u"uy", u""] |
||
| 62 | szabot | 19 | #prefixesn = ur"(?P<npr>(?:(?:fì|tsa)?(?:me|pxe|ay|fra)?|(?:fay)?|(?:tsay)?)(?:fne)?(?:tì|sä)?" |
| 65 | szabot | 20 | prefixes = [u"ay", u"me", u"pxe", u"pe", u"a", u"le", u"nì", u"sä", u"tì", u"ke", u"fì", u"fay", u"tsa", u"tsay", u"fra"] |
| 62 | szabot | 21 | #postfixesv = ur"(?P<vpr>(?:nì|sä|tì|rä'ä |ke )?)" |
| 56 | szabot | 22 | |
| 23 | def parseword(wordin): |
||
| 65 | szabot | 24 | if type(wordin) == type(u"x"): |
| 25 | wordin = wordin.split(" ") |
||
| 26 | ret = {"word": {"id": 0, "navi": u" ".join(wordin), "infix": u"", "type": u""}} |
||
| 27 | foundword = u"" |
||
| 28 | for word in wordlist: |
||
| 29 | foundit = True |
||
| 30 | foundprefs = [] |
||
| 31 | foundposts = [] |
||
| 32 | splitword = word["infix"].split(" ") |
||
| 33 | if len(wordin) != len(splitword): next |
||
| 34 | for wor in range(len(splitword)): |
||
| 35 | foundinf = False |
||
| 36 | foundprefs.append([]) |
||
| 37 | foundposts.append([]) |
||
| 38 | center = u"" |
||
| 39 | foundins = [u"", u"", u""] |
||
| 40 | pre = [] |
||
| 41 | post = [] |
||
| 42 | found = False |
||
| 43 | if u"<1>" in splitword[wor]: |
||
| 44 | for in1 in infixes1: |
||
| 45 | for in2 in infixes2: |
||
| 46 | for in3 in infixes3: |
||
| 47 | if splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3) in wordin[wor]: |
||
| 48 | center = splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3) |
||
| 49 | foundins = [in1, in2, in3] |
||
| 50 | foundinf = True |
||
| 51 | break |
||
| 52 | if foundinf: break |
||
| 53 | if foundinf: break |
||
| 54 | else: |
||
| 55 | if splitword[wor] in wordin[wor]: |
||
| 56 | center = splitword[wor] |
||
| 57 | foundinf = True |
||
| 58 | if not foundinf: |
||
| 59 | foundit = False |
||
| 60 | break |
||
| 61 | pref, posf = wordin[wor].replace(center,u" ").split(" ") |
||
| 62 | for pre in prefixes: |
||
| 63 | if pref.endswith(pre): |
||
| 64 | foundprefs[wor].append(pre) |
||
| 65 | pref = pref[:len(pref)-len(pre)] |
||
| 66 | if pref != u"": |
||
| 67 | foundit = False |
||
| 68 | break |
||
| 69 | foundposts[wor] = posf |
||
| 70 | if foundit == True: |
||
| 71 | foundword = word |
||
| 56 | szabot | 72 | break |
| 65 | szabot | 73 | if foundit == True: |
| 74 | ret["pref"] = foundprefs |
||
| 75 | ret["post"] = foundposts |
||
| 76 | ret["inf"] = foundins |
||
| 77 | ret["word"] = foundword |
||
| 78 | return ret |
||
| 79 | |||
| 80 | #print(parseword([u"tìtìng"])) |
||
| 81 | #print(parseword([u"keykame"])) |
||
| 82 | #print(parseword([u"kameie"])) |
||
| 83 | #print(parseword([u"tìsusiti"])) |
||
| 84 | #print(parseword([u"weykayoeiu"])) |
||
| 85 | #print(parseword([u"yerikit"])) |
||
| 86 | #print(parseword([u"menari"])) |
||
| 87 | #print(parseword([u"menariri"])) |