Rev 77 | Rev 79 | 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"] |
74 | szabot | 14 | #prefixesv = ur"(?P<vpr>(?:nì|sä|tì|rä'ä |ke )?)" |
56 | szabot | 15 | |
16 | def parseword(wordin): |
||
70 | szabot | 17 | ret = {"word": {"id": 0, "navi": u" ".join(wordin), "infix": u"", "type": u""}} |
65 | szabot | 18 | for word in wordlist: |
19 | foundit = True |
||
20 | foundprefs = [] |
||
21 | foundposts = [] |
||
74 | szabot | 22 | splitword = word["infix"].split(u" ") |
23 | if len(wordin) < len(splitword): |
||
68 | szabot | 24 | foundit = False |
25 | next |
||
65 | szabot | 26 | for wor in range(len(splitword)): |
76 | szabot | 27 | if not foundit: |
28 | break |
||
65 | szabot | 29 | foundprefs.append([]) |
30 | foundposts.append([]) |
||
31 | center = u"" |
||
32 | foundins = [u"", u"", u""] |
||
33 | pre = [] |
||
34 | post = [] |
||
35 | if u"<1>" in splitword[wor]: |
||
36 | for in1 in infixes1: |
||
37 | for in2 in infixes2: |
||
38 | for in3 in infixes3: |
||
39 | if splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3) in wordin[wor]: |
||
40 | center = splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3) |
||
41 | foundins = [in1, in2, in3] |
||
42 | break |
||
75 | szabot | 43 | if center != u"": break |
44 | if center != u"": break |
||
65 | szabot | 45 | else: |
46 | if splitword[wor] in wordin[wor]: |
||
47 | center = splitword[wor] |
||
74 | szabot | 48 | if center == u"": |
65 | szabot | 49 | foundit = False |
50 | break |
||
69 | szabot | 51 | pref, posf = wordin[wor].split(center) |
65 | szabot | 52 | for pre in prefixes: |
53 | if pref.endswith(pre): |
||
54 | foundprefs[wor].append(pre) |
||
55 | pref = pref[:len(pref)-len(pre)] |
||
56 | if pref != u"": |
||
57 | foundit = False |
||
58 | break |
||
59 | foundposts[wor] = posf |
||
60 | if foundit == True: |
||
61 | foundword = word |
||
56 | szabot | 62 | break |
65 | szabot | 63 | if foundit == True: |
71 | szabot | 64 | ret["pref"] = foundprefs |
65 | ret["post"] = foundposts |
||
66 | ret["inf"] = foundins |
||
67 | ret["word"] = foundword |
||
77 | szabot | 68 | return ret |
69 | |||
70 | def parsesent(sent): |
||
71 | ret = [] |
||
72 | left = len(sent) |
||
73 | while left: |
||
74 | word = parseword(sent) |
||
78 | szabot | 75 | left -= len(word["word"]["navi"].split(" ")) |
77 | szabot | 76 | ret.append(word) |
70 | szabot | 77 | return ret |