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"]
13
postfixes = [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
 
17
def parseword(wordin):
89 szabot 18
    ret = {"word": {"id": 0, "navi": u"[" + u" ".wordin[0] + u"]", "infix": u"", "type": u""}}
65 szabot 19
    for word in wordlist:
20
        foundit = True
21
        foundprefs = []
22
        foundposts = []
74 szabot 23
        splitword = word["infix"].split(u" ")
24
        if len(wordin) < len(splitword):
68 szabot 25
            foundit = False
26
            next
65 szabot 27
        for wor in range(len(splitword)):
76 szabot 28
            if not foundit:
29
                break
65 szabot 30
            foundprefs.append([])
31
            foundposts.append([])
32
            center = u""
33
            foundins = [u"", u"", u""]
34
            pre = []
35
            post = []
36
            if u"<1>" in splitword[wor]:
37
                for in1 in infixes1:
38
                    for in2 in infixes2:
39
                        for in3 in infixes3:
40
                            if splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3) in wordin[wor]:
41
                                center = splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3)
42
                                foundins = [in1, in2, in3]
43
                                break
75 szabot 44
                        if center != u"": break
45
                    if center != u"": break
65 szabot 46
            else:
47
                if splitword[wor] in wordin[wor]:
48
                    center = splitword[wor]
74 szabot 49
            if center == u"":
65 szabot 50
                foundit = False
51
                break
69 szabot 52
            pref, posf = wordin[wor].split(center)
65 szabot 53
            for pre in prefixes:
54
                if pref.endswith(pre):
55
                    foundprefs[wor].append(pre)
80 szabot 56
                    pref = pref[:-len(pre)]
65 szabot 57
            if pref != u"":
58
                foundit = False
59
                break
80 szabot 60
            for pos in postfixes:
81 szabot 61
                if posf.startswith(pos):
80 szabot 62
                    foundposts[wor].append(pos)
63
                    posf = posf[len(pos):]
82 szabot 64
            if posf != u"":
80 szabot 65
                foundit = False
66
                break
65 szabot 67
        if foundit == True:
68
            foundword = word
56 szabot 69
            break
87 szabot 70
    ret["pref"] = foundprefs
71
    ret["post"] = foundposts
72
    ret["inf"] = foundins
65 szabot 73
    if foundit == True:
71 szabot 74
        ret["word"] = foundword
77 szabot 75
    return ret
76
 
77
def parsesent(sent):
89 szabot 78
    sent = sent.strip().lower()
79
    sent = re.sub(ur"[^\w ]",u"",sent)
80
    sent = re.sub(ur"\ +",u" ",sent)
81
    sent = sent.split(u" ")
77 szabot 82
    ret = []
83
    left = len(sent)
84
    while left:
79 szabot 85
        word = parseword(sent[-left:])
78 szabot 86
        left -= len(word["word"]["navi"].split(" "))
77 szabot 87
        ret.append(word)
70 szabot 88
    return ret