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
 
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""]
93 szabot 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
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"ä"]
62 szabot 14
#prefixesn = ur"(?P<npr>(?:(?:fì|tsa)?(?:me|pxe|ay|fra)?|(?:fay)?|(?:tsay)?)(?:fne)?(?:tì|sä)?"
74 szabot 15
#prefixesv = ur"(?P<vpr>(?:nì|sä|tì|rä'ä |ke )?)"
56 szabot 16
 
91 szabot 17
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""))
18
 
56 szabot 19
def parseword(wordin):
90 szabot 20
    ret = {"word": {"id": 0, "navi": u"[" + wordin[0] + u"]", "infix": u"", "type": u""}}
65 szabot 21
    for word in wordlist:
22
        foundit = True
23
        foundprefs = []
24
        foundposts = []
74 szabot 25
        splitword = word["infix"].split(u" ")
26
        if len(wordin) < len(splitword):
68 szabot 27
            foundit = False
28
            next
65 szabot 29
        for wor in range(len(splitword)):
76 szabot 30
            if not foundit:
31
                break
65 szabot 32
            foundprefs.append([])
33
            foundposts.append([])
34
            center = u""
35
            foundins = [u"", u"", u""]
36
            pre = []
37
            post = []
38
            if u"<1>" in splitword[wor]:
39
                for in1 in infixes1:
40
                    for in2 in infixes2:
41
                        for in3 in infixes3:
42
                            if splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3) in wordin[wor]:
43
                                center = splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3)
44
                                foundins = [in1, in2, in3]
45
                                break
75 szabot 46
                        if center != u"": break
47
                    if center != u"": break
65 szabot 48
            else:
49
                if splitword[wor] in wordin[wor]:
50
                    center = splitword[wor]
91 szabot 51
                else:
52
                    for i in lenit:
92 szabot 53
                        temp = u""
91 szabot 54
                        if splitword[wor].startswith(i[0]):
92 szabot 55
                            temp = i[1] + splitword[wor][len(i[0]):]
56
                            if temp in wordin[wor]:
57
                                center = temp
91 szabot 58
 
74 szabot 59
            if center == u"":
65 szabot 60
                foundit = False
61
                break
91 szabot 62
            temp = wordin[wor].split(center)
63
            if len(temp) != 2:
64
                foundit = False
65
                break
66
            pref, posf = temp
93 szabot 67
            for pre in prefixes:
68
                if pref.endswith(pre):
69
                    foundprefs[wor].append(pre)
70
                    pref = pref[:-len(pre)]
65 szabot 71
            if pref != u"":
72
                foundit = False
73
                break
93 szabot 74
            for pos in postfixes:
75
                if posf.startswith(pos):
76
                    foundposts[wor].append(pos)
77
                    posf = posf[len(pos):]
82 szabot 78
            if posf != u"":
80 szabot 79
                foundit = False
80
                break
65 szabot 81
        if foundit == True:
82
            foundword = word
56 szabot 83
            break
87 szabot 84
    ret["pref"] = foundprefs
85
    ret["post"] = foundposts
86
    ret["inf"] = foundins
65 szabot 87
    if foundit == True:
71 szabot 88
        ret["word"] = foundword
77 szabot 89
    return ret
90
 
91
def parsesent(sent):
89 szabot 92
    sent = sent.strip().lower()
91 szabot 93
    sent = re.sub(ur"[^\wìä ]",u"",sent)
89 szabot 94
    sent = re.sub(ur"\ +",u" ",sent)
95
    sent = sent.split(u" ")
77 szabot 96
    ret = []
97
    left = len(sent)
98
    while left:
79 szabot 99
        word = parseword(sent[-left:])
78 szabot 100
        left -= len(word["word"]["navi"].split(" "))
77 szabot 101
        ret.append(word)
70 szabot 102
    return ret