Subversion Repositories navi

Rev

Rev 73 | Rev 75 | 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""]
62 szabot 12
#prefixesn = ur"(?P<npr>(?:(?:fì|tsa)?(?:me|pxe|ay|fra)?|(?:fay)?|(?:tsay)?)(?:fne)?(?:tì|sä)?"
65 szabot 13
prefixes = [u"ay", u"me", u"pxe", u"pe", u"a", u"le", u"nì", u"sä", u"tì", u"ke", u"fì", u"fay", u"tsa", u"tsay", u"fra"]
74 szabot 14
#prefixesv = ur"(?P<vpr>(?:nì|sä|tì|rä'ä |ke )?)"
56 szabot 15
 
16
def parseword(wordin):
70 szabot 17
    ret = {"word": {"id": 0, "navi": u" ".join(wordin), "infix": u"", "type": u""}}
65 szabot 18
    foundword = u""
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)):
28
            foundprefs.append([])
29
            foundposts.append([])
30
            center = u""
31
            foundins = [u"", u"", u""]
32
            pre = []
33
            post = []
34
            found = False
35
            if u"<1>" in splitword[wor]:
36
                for in1 in infixes1:
37
                    for in2 in infixes2:
38
                        for in3 in infixes3:
39
                            if splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3) in wordin[wor]:
40
                                center = splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3)
41
                                foundins = [in1, in2, in3]
42
                                break
43
                        if foundinf: break
44
                    if foundinf: break
45
            else:
46
                if splitword[wor] in wordin[wor]:
47
                    center = splitword[wor]
74 szabot 48
            if center == u"":
65 szabot 49
                foundit = False
50
                break
69 szabot 51
            pref, posf = wordin[wor].split(center)
65 szabot 52
            for pre in prefixes:
53
                if pref.endswith(pre):
54
                    foundprefs[wor].append(pre)
55
                    pref = pref[:len(pref)-len(pre)]
56
            if pref != u"":
57
                foundit = False
58
                break
59
            foundposts[wor] = posf
60
        if foundit == True:
61
            foundword = word
56 szabot 62
            break
65 szabot 63
    if foundit == True:
71 szabot 64
        ret["pref"] = foundprefs
65
        ret["post"] = foundposts
66
        ret["inf"] = foundins
67
        ret["word"] = foundword
70 szabot 68
    return ret