Rev 65 | 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 |
||
93 | szabot | 79 | for pre in prefixes: |
94 | szabot | 80 | if pref != u"": |
81 | if pref.endswith(pre): |
||
82 | foundprefs[wor].append(pre) |
||
83 | pref = pref[:-len(pre)] |
||
65 | szabot | 84 | if pref != u"": |
85 | foundit = False |
||
86 | break |
||
93 | szabot | 87 | for pos in postfixes: |
94 | szabot | 88 | if posf != u"": |
89 | if posf.startswith(pos): |
||
90 | foundposts[wor].append(pos) |
||
91 | posf = posf[len(pos):] |
||
82 | szabot | 92 | if posf != u"": |
80 | szabot | 93 | foundit = False |
94 | break |
||
65 | szabot | 95 | if foundit == True: |
96 | foundword = word |
||
56 | szabot | 97 | break |
87 | szabot | 98 | ret["pref"] = foundprefs |
99 | ret["post"] = foundposts |
||
100 | ret["inf"] = foundins |
||
99 | szabot | 101 | ret["len"] = lenited |
65 | szabot | 102 | if foundit == True: |
71 | szabot | 103 | ret["word"] = foundword |
77 | szabot | 104 | return ret |
105 | |||
106 | def parsesent(sent): |
||
101 | szabot | 107 | sent = sent.strip().lower().replace(u"’", u"'") |
100 | szabot | 108 | sent = re.sub(ur"[^\wìä' ]",u"",sent) |
89 | szabot | 109 | sent = re.sub(ur"\ +",u" ",sent) |
110 | sent = sent.split(u" ") |
||
77 | szabot | 111 | ret = [] |
112 | left = len(sent) |
||
113 | while left: |
||
108 | szabot | 114 | word = parsenum.parse(sent[len(sent)-left]) |
103 | szabot | 115 | if word == None: |
116 | word = parseword(sent[-left:]) |
||
78 | szabot | 117 | left -= len(word["word"]["navi"].split(" ")) |
77 | szabot | 118 | ret.append(word) |
110 | muzer | 119 | return ret |