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