Subversion Repositories navi

Rev

Rev 49 | Go to most recent revision | Details | 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"""):
15
        if row["partOfSpeech"] in (u"v.", u"vin.", u"vtr."):
16
            current = unicode(row["ipa"])
17
            current = current.replace(ur"ɛ",ur"e").replace(ur".",ur"").replace(ur"ɾ",ur"r") \
18
           .replace(ur"ɪ",ur"ì").replace(ur"ˈ",ur"").replace(ur"'",ur"x") \
19
           .replace(ur"ŋ",ur"ng").replace(ur"j",ur"y").replace(ur"ʔ",ur"'") \
20
           .replace(ur"æ",ur"ä").replace(ur"ˌ",ur"").replace(ur"\t{ts}",ur"ts") \
21
           .replace(ur"ṛ",ur"rr").replace(ur"ḷ",ur"ll").replace(ur"k̚",ur"k ") \
22
           .replace(ur"p̚",ur"p ").replace(ur"t̚",ur"t ").replace(ur"'̚",ur"' ") \
23
           .replace(u"\\",ur"").replace(ur"(",ur"").replace(ur")",ur"") \
24
           .replace(ur"[",ur"").replace(ur"]",ur"").replace(ur"  "," ") \
25
           .strip()
26
            current = re.sub(ur" or.*","",current)
27
            current = re.sub(ur"z(.*)engk(.*)e",ur"z\1enk\2e",current)
28
            current = re.sub(ur"t(.*)ì(m|n)\ ",ur"t\1ìng ",current)
29
            current = current.split(ur"$cdot$")
30
            if len(current) == 3:
31
                current = current[0] + u"<0><1>" + current[1] + u"<2>" + current[2]
32
            elif len(current) == 2:
33
                current = current[0] + u"<0><1><2>" + current[1]
34
            else:
35
                current = u"<0><1><2>" + current[0]
36
        else:
37
            current = unicode(row["navi"])
38
        ret.append([row["id"], row["navi"], current, row["partOfSpeech"]])
39
    db.close()
40
    return ret
41
 
42
def getnavi(word):
43
    ret = []
44
    db = tornado.database.Connection("127.0.0.1", "navi", user="navi", password="navi")
45
    for row in db.query("""
46
    SELECT *
47
    FROM `metaWords`
48
    WHERE navi = ?""",word):
49
        ret.append([row["id"],row["navi"], row["infix"], row["partOfSpeech"]])
50
    db.close()
51
    return ret
52