Subversion Repositories navi

Rev

Rev 97 | Rev 99 | 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 = []
74 szabot 26
        splitword = word["infix"].split(u" ")
27
        if len(wordin) < len(splitword):
68 szabot 28
            foundit = False
29
            next
65 szabot 30
        for wor in range(len(splitword)):
76 szabot 31
            if not foundit:
32
                break
65 szabot 33
            foundprefs.append([])
34
            foundposts.append([])
35
            center = u""
36
            foundins = [u"", u"", u""]
37
            pre = []
38
            post = []
39
            if u"<1>" in splitword[wor]:
40
                for in1 in infixes1:
41
                    for in2 in infixes2:
42
                        for in3 in infixes3:
43
                            if splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3) in wordin[wor]:
44
                                center = splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3)
45
                                foundins = [in1, in2, in3]
46
                                break
75 szabot 47
                        if center != u"": break
48
                    if center != u"": break
65 szabot 49
            else:
50
                if splitword[wor] in wordin[wor]:
51
                    center = splitword[wor]
95 szabot 52
                if center == u"":
91 szabot 53
                    for i in lenit:
92 szabot 54
                        temp = u""
91 szabot 55
                        if splitword[wor].startswith(i[0]):
92 szabot 56
                            temp = i[1] + splitword[wor][len(i[0]):]
57
                            if temp in wordin[wor]:
58
                                center = temp
95 szabot 59
                if center == u"":
60
                    if splitword[wor].endswith(u"nga"):
97 szabot 61
                        temp = splitword[wor][:-3] + u"ng"
95 szabot 62
                        if temp in wordin[wor]:
63
                            center = temp
74 szabot 64
            if center == u"":
65 szabot 65
                foundit = False
66
                break
91 szabot 67
            temp = wordin[wor].split(center)
68
            if len(temp) != 2:
69
                foundit = False
70
                break
71
            pref, posf = temp
93 szabot 72
            for pre in prefixes:
94 szabot 73
                if pref != u"":
74
                    if pref.endswith(pre):
75
                        foundprefs[wor].append(pre)
76
                        pref = pref[:-len(pre)]
65 szabot 77
            if pref != u"":
78
                foundit = False
79
                break
93 szabot 80
            for pos in postfixes:
94 szabot 81
                if posf != u"":
82
                    if posf.startswith(pos):
83
                        foundposts[wor].append(pos)
84
                        posf = posf[len(pos):]
82 szabot 85
            if posf != u"":
80 szabot 86
                foundit = False
87
                break
65 szabot 88
        if foundit == True:
89
            foundword = word
56 szabot 90
            break
87 szabot 91
    ret["pref"] = foundprefs
92
    ret["post"] = foundposts
93
    ret["inf"] = foundins
65 szabot 94
    if foundit == True:
71 szabot 95
        ret["word"] = foundword
77 szabot 96
    return ret
97
 
98
def parsesent(sent):
89 szabot 99
    sent = sent.strip().lower()
91 szabot 100
    sent = re.sub(ur"[^\wìä ]",u"",sent)
89 szabot 101
    sent = re.sub(ur"\ +",u" ",sent)
102
    sent = sent.split(u" ")
77 szabot 103
    ret = []
104
    left = len(sent)
105
    while left:
79 szabot 106
        word = parseword(sent[-left:])
78 szabot 107
        left -= len(word["word"]["navi"].split(" "))
77 szabot 108
        ret.append(word)
70 szabot 109
    return ret