Rev 68 | Rev 70 | 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 |
||
66 | szabot | 5 | import dbconnector |
56 | szabot | 6 | |
65 | szabot | 7 | wordlist = dbconnector.getnavilist() |
8 | |||
9 | infixes1 = [u"awn", u"eyk", u"us", u"äp", u""] |
||
10 | 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""] |
||
11 | infixes3 = [u"äng", u"ats", u"eiy", u"ei", u"uy", u""] |
||
62 | szabot | 12 | #prefixesn = ur"(?P<npr>(?:(?:fì|tsa)?(?:me|pxe|ay|fra)?|(?:fay)?|(?:tsay)?)(?:fne)?(?:tì|sä)?" |
65 | szabot | 13 | 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 | 14 | #postfixesv = ur"(?P<vpr>(?:nì|sä|tì|rä'ä |ke )?)" |
56 | szabot | 15 | |
16 | def parseword(wordin): |
||
68 | szabot | 17 | wordin = wordin.split(" ") |
69 | szabot | 18 | ret = [{"word": {"id": 0, "navi": u" ".join(wordin), "infix": u"", "type": u""}}] |
65 | szabot | 19 | foundword = u"" |
20 | for word in wordlist: |
||
69 | szabot | 21 | foundinf = False |
65 | szabot | 22 | foundit = True |
23 | foundprefs = [] |
||
24 | foundposts = [] |
||
25 | splitword = word["infix"].split(" ") |
||
69 | szabot | 26 | if len(wordin) < len(splitword): |
68 | szabot | 27 | foundit = False |
28 | next |
||
65 | szabot | 29 | for wor in range(len(splitword)): |
30 | foundprefs.append([]) |
||
31 | foundposts.append([]) |
||
32 | center = u"" |
||
33 | foundins = [u"", u"", u""] |
||
34 | pre = [] |
||
35 | post = [] |
||
36 | found = False |
||
37 | if u"<1>" in splitword[wor]: |
||
38 | for in1 in infixes1: |
||
39 | for in2 in infixes2: |
||
40 | for in3 in infixes3: |
||
41 | if splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3) in wordin[wor]: |
||
42 | center = splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3) |
||
43 | foundins = [in1, in2, in3] |
||
44 | foundinf = True |
||
45 | break |
||
46 | if foundinf: break |
||
47 | if foundinf: break |
||
48 | else: |
||
49 | if splitword[wor] in wordin[wor]: |
||
50 | center = splitword[wor] |
||
51 | foundinf = True |
||
52 | if not foundinf: |
||
53 | foundit = False |
||
54 | break |
||
69 | szabot | 55 | pref, posf = wordin[wor].split(center) |
65 | szabot | 56 | for pre in prefixes: |
57 | if pref.endswith(pre): |
||
58 | foundprefs[wor].append(pre) |
||
59 | pref = pref[:len(pref)-len(pre)] |
||
60 | if pref != u"": |
||
61 | foundit = False |
||
62 | break |
||
63 | foundposts[wor] = posf |
||
64 | if foundit == True: |
||
65 | foundword = word |
||
56 | szabot | 66 | break |
65 | szabot | 67 | if foundit == True: |
69 | szabot | 68 | ret[0]["pref"] = foundprefs |
69 | ret[0]["post"] = foundposts |
||
70 | ret[0]["inf"] = foundins |
||
71 | ret[0]["word"] = foundword |
||
72 | if len(wordin) > len(splitword): |
||
73 | return ret + parseword(u" ".join(wordin[len(splitword):])) |
||
74 | else: |
||
75 | return ret |