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""]
83 szabot 12
prefixes = [u"tsay", u"fay", u"tsa", u"fra", u"pxe", u"ay", u"me", u"pe", u"le", u"nì", u"sä", u"tì", u"ke", u"fì", u"a"]
91 szabot 13
postfixes = [u"tsyìp", u"eyä", u"ìri", u"an", 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"e", u"l", u"o", 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:
53
                        if splitword[wor].startswith(i[0]):
54
                            splitword[wor][:len(i[0])] = i[1]
55
                            if splitword[wor] in wordin[wor]:
56
                                center = splitword[wor]
57
 
74 szabot 58
            if center == u"":
65 szabot 59
                foundit = False
60
                break
91 szabot 61
            temp = wordin[wor].split(center)
62
            if len(temp) != 2:
63
                foundit = False
64
                break
65
            pref, posf = temp
66
            last = u""
67
            while pref != last:
68
                last = pref
69
                for pre in prefixes:
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
91 szabot 76
            last = u""
77
            while posf != last:
78
                for pos in postfixes:
79
                    if posf.startswith(pos):
80
                        foundposts[wor].append(pos)
81
                        posf = posf[len(pos):]
82 szabot 82
            if posf != u"":
80 szabot 83
                foundit = False
84
                break
65 szabot 85
        if foundit == True:
86
            foundword = word
56 szabot 87
            break
87 szabot 88
    ret["pref"] = foundprefs
89
    ret["post"] = foundposts
90
    ret["inf"] = foundins
65 szabot 91
    if foundit == True:
71 szabot 92
        ret["word"] = foundword
77 szabot 93
    return ret
94
 
95
def parsesent(sent):
89 szabot 96
    sent = sent.strip().lower()
91 szabot 97
    sent = re.sub(ur"[^\wìä ]",u"",sent)
89 szabot 98
    sent = re.sub(ur"\ +",u" ",sent)
99
    sent = sent.split(u" ")
77 szabot 100
    ret = []
101
    left = len(sent)
102
    while left:
79 szabot 103
        word = parseword(sent[-left:])
78 szabot 104
        left -= len(word["word"]["navi"].split(" "))
77 szabot 105
        ret.append(word)
70 szabot 106
    return ret