Subversion Repositories navi

Rev

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
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")
14
postfixes = (u"an", 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]
91 szabot 52
                else:
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
91 szabot 59
 
74 szabot 60
            if center == u"":
65 szabot 61
                foundit = False
62
                break
91 szabot 63
            temp = wordin[wor].split(center)
64
            if len(temp) != 2:
65
                foundit = False
66
                break
67
            pref, posf = temp
93 szabot 68
            for pre in prefixes:
94 szabot 69
                if pref != u"":
70
                    if pref.endswith(pre):
71
                        foundprefs[wor].append(pre)
72
                        pref = pref[:-len(pre)]
65 szabot 73
            if pref != u"":
74
                foundit = False
75
                break
93 szabot 76
            for pos in postfixes:
94 szabot 77
                if posf != u"":
78
                    if posf.startswith(pos):
79
                        foundposts[wor].append(pos)
80
                        posf = posf[len(pos):]
82 szabot 81
            if posf != u"":
80 szabot 82
                foundit = False
83
                break
65 szabot 84
        if foundit == True:
85
            foundword = word
56 szabot 86
            break
87 szabot 87
    ret["pref"] = foundprefs
88
    ret["post"] = foundposts
89
    ret["inf"] = foundins
65 szabot 90
    if foundit == True:
71 szabot 91
        ret["word"] = foundword
77 szabot 92
    return ret
93
 
94
def parsesent(sent):
89 szabot 95
    sent = sent.strip().lower()
91 szabot 96
    sent = re.sub(ur"[^\wìä ]",u"",sent)
89 szabot 97
    sent = re.sub(ur"\ +",u" ",sent)
98
    sent = sent.split(u" ")
77 szabot 99
    ret = []
100
    left = len(sent)
101
    while left:
79 szabot 102
        word = parseword(sent[-left:])
78 szabot 103
        left -= len(word["word"]["navi"].split(" "))
77 szabot 104
        ret.append(word)
70 szabot 105
    return ret