Rev 117 | Rev 120 | 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 |
103 | szabot | 6 | import parsenum |
56 | szabot | 7 | |
65 | szabot | 8 | wordlist = dbconnector.getnavilist() |
9 | |||
94 | szabot | 10 | infixes1 = (u"awn", u"eyk", u"us", u"äp", u"") |
11 | 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"") |
||
12 | infixes3 = (u"äng", u"ats", u"eiy", u"ei", u"uy", u"") |
||
112 | muzer | 13 | prefixes = (u"tsay", u"fay", u"fra", u"pxe", u"fne", u"tsa", u"pe", u"le", u"nì", u"sä", u"tì", u"ay", u"me", u"fì", u"ke", u"a") |
14 | adpositions = (u"mungwrr", u"kxamlä", u"pximaw", u"pxisre", u"tafkip", u"nemfa", u"takip", u"mìkam", u"teri", u"fkip", u"luke", u"pxel", u"pxaw", u"rofa", u"ìla", u"fpi", u"ftu", u"kip", u"lok", u"maw", u"sre", u"sìn", u"vay", u"eo", u"fa", u"hu", u"io", u"ka", u"mì", u"na", u"ne", u"ro", u"ta", u"uo", u"wä", u"äo", u"to") |
||
116 | muzer | 15 | postfixes = adpositions + (u"tsyìp", u"eyä", u"ìri", u"ìl", u"it", u"lo", u"ri", u"ru", u"ti", u"ur", u"ve", u"yä", u"ya", u"tu", u"vi", u"yu", u"an", u"ng", u"e", u"o", u"l", u"t", u"y", u"a", u"ä", u"r") |
62 | szabot | 16 | #prefixesn = ur"(?P<npr>(?:(?:fì|tsa)?(?:me|pxe|ay|fra)?|(?:fay)?|(?:tsay)?)(?:fne)?(?:tì|sä)?" |
74 | szabot | 17 | #prefixesv = ur"(?P<vpr>(?:nì|sä|tì|rä'ä |ke )?)" |
56 | szabot | 18 | |
91 | szabot | 19 | lenit = ((u"px", u"p"), (u"tx", u"t"), (u"kx", u"k"), (u"ts", u"s"), (u"t", u"s"), (u"p", u"f"), (u"k", u"h"), (u"'", u"")) |
20 | |||
56 | szabot | 21 | def parseword(wordin): |
90 | szabot | 22 | ret = {"word": {"id": 0, "navi": u"[" + wordin[0] + u"]", "infix": u"", "type": u""}} |
65 | szabot | 23 | for word in wordlist: |
24 | foundit = True |
||
25 | foundprefs = [] |
||
26 | foundposts = [] |
||
99 | szabot | 27 | lenited = False |
74 | szabot | 28 | splitword = word["infix"].split(u" ") |
29 | if len(wordin) < len(splitword): |
||
68 | szabot | 30 | foundit = False |
31 | next |
||
65 | szabot | 32 | for wor in range(len(splitword)): |
76 | szabot | 33 | if not foundit: |
34 | break |
||
65 | szabot | 35 | foundprefs.append([]) |
36 | foundposts.append([]) |
||
37 | center = u"" |
||
38 | foundins = [u"", u"", u""] |
||
39 | pre = [] |
||
40 | post = [] |
||
41 | if u"<1>" in splitword[wor]: |
||
42 | for in1 in infixes1: |
||
43 | for in2 in infixes2: |
||
44 | for in3 in infixes3: |
||
45 | if splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3) in wordin[wor]: |
||
46 | center = splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3) |
||
47 | foundins = [in1, in2, in3] |
||
48 | break |
||
75 | szabot | 49 | if center != u"": break |
50 | if center != u"": break |
||
65 | szabot | 51 | else: |
52 | if splitword[wor] in wordin[wor]: |
||
53 | center = splitword[wor] |
||
95 | szabot | 54 | if center == u"": |
91 | szabot | 55 | for i in lenit: |
92 | szabot | 56 | temp = u"" |
91 | szabot | 57 | if splitword[wor].startswith(i[0]): |
92 | szabot | 58 | temp = i[1] + splitword[wor][len(i[0]):] |
59 | if temp in wordin[wor]: |
||
99 | szabot | 60 | lenited = True |
92 | szabot | 61 | center = temp |
95 | szabot | 62 | if center == u"": |
63 | if splitword[wor].endswith(u"nga"): |
||
97 | szabot | 64 | temp = splitword[wor][:-3] + u"ng" |
95 | szabot | 65 | if temp in wordin[wor]: |
66 | center = temp |
||
103 | szabot | 67 | if splitword[wor].endswith(u"po"): |
68 | temp = splitword[wor][:-3] + u"p" |
||
69 | if temp in wordin[wor]: |
||
70 | center = temp |
||
74 | szabot | 71 | if center == u"": |
65 | szabot | 72 | foundit = False |
73 | break |
||
91 | szabot | 74 | temp = wordin[wor].split(center) |
75 | if len(temp) != 2: |
||
76 | foundit = False |
||
77 | break |
||
78 | pref, posf = temp |
||
119 | szabot | 79 | last = u"" |
80 | while last != pref: |
||
81 | last = pref |
||
82 | for pre in prefixes: |
||
83 | if pref != u"": |
||
84 | if pref.endswith(pre): |
||
85 | if pre in foundprefs[wor]: |
||
86 | break |
||
87 | foundprefs[wor].append(pre) |
||
88 | pref = pref[:-len(pre)] |
||
65 | szabot | 89 | if pref != u"": |
90 | foundit = False |
||
91 | break |
||
119 | szabot | 92 | last = u"" |
93 | while last != posf: |
||
94 | last = posf |
||
95 | for pos in postfixes: |
||
96 | if posf != u"": |
||
97 | if posf.startswith(pos): |
||
98 | if pos in foundposts[wor]: |
||
99 | break |
||
100 | foundposts[wor].append(pos) |
||
101 | posf = posf[len(pos):] |
||
82 | szabot | 102 | if posf != u"": |
80 | szabot | 103 | foundit = False |
104 | break |
||
65 | szabot | 105 | if foundit == True: |
106 | foundword = word |
||
56 | szabot | 107 | break |
87 | szabot | 108 | ret["pref"] = foundprefs |
109 | ret["post"] = foundposts |
||
110 | ret["inf"] = foundins |
||
99 | szabot | 111 | ret["len"] = lenited |
65 | szabot | 112 | if foundit == True: |
71 | szabot | 113 | ret["word"] = foundword |
77 | szabot | 114 | return ret |
115 | |||
116 | def parsesent(sent): |
||
101 | szabot | 117 | sent = sent.strip().lower().replace(u"’", u"'") |
100 | szabot | 118 | sent = re.sub(ur"[^\wìä' ]",u"",sent) |
89 | szabot | 119 | sent = re.sub(ur"\ +",u" ",sent) |
120 | sent = sent.split(u" ") |
||
77 | szabot | 121 | ret = [] |
122 | left = len(sent) |
||
123 | while left: |
||
108 | szabot | 124 | word = parsenum.parse(sent[len(sent)-left]) |
103 | szabot | 125 | if word == None: |
126 | word = parseword(sent[-left:]) |
||
78 | szabot | 127 | left -= len(word["word"]["navi"].split(" ")) |
77 | szabot | 128 | ret.append(word) |
110 | muzer | 129 | return ret |