Subversion Repositories navi

Rev

Rev 66 | Rev 69 | 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
#wordlist = [{"id": 1, "navi": u"si", "infix": u"s<1><2><3>i", "type": u"v."},
10
            #{"id": 2, "navi": u"wou", "infix": u"w<1><2>o<3>u", "type": u"v."},
11
            #{"id": 3, "navi": u"kame", "infix": u"k<1><2>am<3>e", "type": u"v."},
12
            #{"id": 4, "navi": u"tìng", "infix": u"t<1><2><3>ìng", "type": u"v."},
13
            #{"id": 5, "navi": u"yerik", "infix": u"yerik", "type": u"n."},
14
            #{"id": 6, "navi": u"nari", "infix": u"nari", "type": u"n."}]
15
 
16
infixes1 = [u"awn", u"eyk", u"us", u"äp", u""]
17
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""]
18
infixes3 = [u"äng", u"ats", u"eiy", u"ei", u"uy", u""]
62 szabot 19
#prefixesn = ur"(?P<npr>(?:(?:fì|tsa)?(?:me|pxe|ay|fra)?|(?:fay)?|(?:tsay)?)(?:fne)?(?:tì|sä)?"
65 szabot 20
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"]
62 szabot 21
#postfixesv = ur"(?P<vpr>(?:nì|sä|tì|rä'ä |ke )?)"
56 szabot 22
 
23
def parseword(wordin):
68 szabot 24
    wordin = wordin.split(" ")
65 szabot 25
    ret = {"word": {"id": 0, "navi": u" ".join(wordin), "infix": u"", "type": u""}}
26
    foundword = u""
27
    for word in wordlist:
28
        foundit = True
29
        foundprefs = []
30
        foundposts = []
31
        splitword = word["infix"].split(" ")
68 szabot 32
        if len(wordin) != len(splitword):
33
            foundit = False
34
            next
65 szabot 35
        for wor in range(len(splitword)):
36
            foundinf = False
37
            foundprefs.append([])
38
            foundposts.append([])
39
            center = u""
40
            foundins = [u"", u"", u""]
41
            pre = []
42
            post = []
43
            found = False
44
            if u"<1>" in splitword[wor]:
45
                for in1 in infixes1:
46
                    for in2 in infixes2:
47
                        for in3 in infixes3:
48
                            if splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3) in wordin[wor]:
49
                                center = splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3)
50
                                foundins = [in1, in2, in3]
51
                                foundinf = True
52
                                break
53
                        if foundinf: break
54
                    if foundinf: break
55
            else:
56
                if splitword[wor] in wordin[wor]:
57
                    center = splitword[wor]
58
                    foundinf = True
59
            if not foundinf:
60
                foundit = False
61
                break
62
            pref, posf = wordin[wor].replace(center,u" ").split(" ")
63
            for pre in prefixes:
64
                if pref.endswith(pre):
65
                    foundprefs[wor].append(pre)
66
                    pref = pref[:len(pref)-len(pre)]
67
            if pref != u"":
68
                foundit = False
69
                break
70
            foundposts[wor] = posf
71
        if foundit == True:
72
            foundword = word
56 szabot 73
            break
65 szabot 74
    if foundit == True:
75
        ret["pref"] = foundprefs
76
        ret["post"] = foundposts
77
        ret["inf"] = foundins
78
        ret["word"] = foundword
79
    return ret
80
 
81
#print(parseword([u"tìtìng"]))
82
#print(parseword([u"keykame"]))
83
#print(parseword([u"kameie"]))
84
#print(parseword([u"tìsusiti"]))
85
#print(parseword([u"weykayoeiu"]))
86
#print(parseword([u"yerikit"]))
87
#print(parseword([u"menari"]))
88
#print(parseword([u"menariri"]))