Subversion Repositories navi

Rev

Rev 46 | Rev 89 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
46 szabot 1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
 
4
import tornado.database
5
import re
6
 
7
def getnavilist():
8
    ret = []
9
    current = u""
10
    db = tornado.database.Connection("127.0.0.1", "navi", user="navi", password="navi")
11
    for row in db.query("""
12
    SELECT *, CHAR_LENGTH(navi) AS NL
13
    FROM `metaWords`
14
    ORDER BY NL DESC"""):
49 szabot 15
        infix = makeinfix(row)
16
        ret.append([row["id"], row["navi"], infix, row["partOfSpeech"]])
46 szabot 17
    db.close()
18
    return ret
19
 
20
def getnavi(word):
21
    ret = []
22
    db = tornado.database.Connection("127.0.0.1", "navi", user="navi", password="navi")
23
    for row in db.query("""
24
    SELECT *
25
    FROM `metaWords`
26
    WHERE navi = ?""",word):
49 szabot 27
        infix = makeinfix(row)
28
        ret.append([row["id"],row["navi"], infix, row["partOfSpeech"]])
46 szabot 29
    db.close()
30
    return ret
49 szabot 31
 
32
def makeinfix(row):
33
    if row["partOfSpeech"] in (u"v.", u"vin.", u"vtr."):
34
        current = unicode(row["ipa"])
35
        current = current.replace(ur"ɛ",ur"e").replace(ur".",ur"").replace(ur"ɾ",ur"r") \
36
       .replace(ur"ɪ",ur"ì").replace(ur"ˈ",ur"").replace(ur"'",ur"x") \
37
       .replace(ur"ŋ",ur"ng").replace(ur"j",ur"y").replace(ur"ʔ",ur"'") \
38
       .replace(ur"æ",ur"ä").replace(ur"ˌ",ur"").replace(ur"\t{ts}",ur"ts") \
39
       .replace(ur"ṛ",ur"rr").replace(ur"ḷ",ur"ll").replace(ur"k̚",ur"k ") \
40
       .replace(ur"p̚",ur"p ").replace(ur"t̚",ur"t ").replace(ur"'̚",ur"' ") \
41
       .replace(u"\\",ur"").replace(ur"(",ur"").replace(ur")",ur"") \
42
       .replace(ur"[",ur"").replace(ur"]",ur"").replace(ur"  "," ") \
43
       .strip()
44
        current = re.sub(ur" or.*","",current)
45
        current = re.sub(ur"z(.*)engk(.*)e",ur"z\1enk\2e",current)
46
        current = re.sub(ur"t(.*)ì(m|n)\ ",ur"t\1ìng ",current)
47
        current = current.split(ur"$cdot$")
48
        if len(current) == 3:
49
            current = current[0] + u"<0><1>" + current[1] + u"<2>" + current[2]
50
        elif len(current) == 2:
51
            current = current[0] + u"<0><1><2>" + current[1]
52
        else:
53
            current = u"<0><1><2>" + current[0]
54
    else:
55
        current = unicode(row["navi"])
56
    return current
57
 
58
#def gettrans(id, cod):
59
    #ret = []
60
    #if cod not in (u"est",u"ptbr",u"de",u"eng",u"all"):
61
        #return ret
62
    #db = tornado.database.Connection("127.0.0.1", "navi", user="navi", password="navi")
63
    #if cod == "all":
64
            #for row in db.query("""
65
            #SELECT *
66
            #FROM `metaWords`
67
            #WHERE id = ?""",idd):
68
                #infix = makeinfix(row)
69
            #ret.append([row["id"],row["navi"], infix, row["partOfSpeech"]])
70
    #db.close()