Rev 155 | Rev 171 | 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"") |
||
156 | muzer | 13 | prefixes = (u"tsay", u"say", u"fay", u"fra", u"pxe", u"fne", u"tsa", u"sa", u"pe", u"fe", u"le", u"nì", u"sä", u"tì", u"sì", u"ay", u"me", u"fì", u"ke", u"he", u"a") |
112 | muzer | 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") |
121 | szabot | 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"ke", 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)] |
||
120 | szabot | 89 | break |
65 | szabot | 90 | if pref != u"": |
91 | foundit = False |
||
92 | break |
||
119 | szabot | 93 | last = u"" |
94 | while last != posf: |
||
95 | last = posf |
||
96 | for pos in postfixes: |
||
97 | if posf != u"": |
||
98 | if posf.startswith(pos): |
||
99 | if pos in foundposts[wor]: |
||
100 | break |
||
101 | foundposts[wor].append(pos) |
||
102 | posf = posf[len(pos):] |
||
120 | szabot | 103 | break |
82 | szabot | 104 | if posf != u"": |
80 | szabot | 105 | foundit = False |
106 | break |
||
65 | szabot | 107 | if foundit == True: |
108 | foundword = word |
||
56 | szabot | 109 | break |
87 | szabot | 110 | ret["pref"] = foundprefs |
111 | ret["post"] = foundposts |
||
112 | ret["inf"] = foundins |
||
99 | szabot | 113 | ret["len"] = lenited |
65 | szabot | 114 | if foundit == True: |
71 | szabot | 115 | ret["word"] = foundword |
77 | szabot | 116 | return ret |
117 | |||
118 | def parsesent(sent): |
||
101 | szabot | 119 | sent = sent.strip().lower().replace(u"’", u"'") |
100 | szabot | 120 | sent = re.sub(ur"[^\wìä' ]",u"",sent) |
89 | szabot | 121 | sent = re.sub(ur"\ +",u" ",sent) |
122 | sent = sent.split(u" ") |
||
77 | szabot | 123 | ret = [] |
124 | left = len(sent) |
||
125 | while left: |
||
108 | szabot | 126 | word = parsenum.parse(sent[len(sent)-left]) |
103 | szabot | 127 | if word == None: |
128 | word = parseword(sent[-left:]) |
||
78 | szabot | 129 | left -= len(word["word"]["navi"].split(" ")) |
77 | szabot | 130 | ret.append(word) |
136 | muzer | 131 | return ret |