Subversion Repositories navi

Rev

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

#!/usr/bin/python
# -*- coding: utf-8 -*-

import tornado.database
import re

def getnavilist():
    ret = []
    current = u""
    db = tornado.database.Connection("127.0.0.1", "navi", user="navi", password="navi")
    for row in db.query("""
    SELECT *, CHAR_LENGTH(navi) AS NL
    FROM `metaWords`
    ORDER BY NL DESC"""
):
        infix = makeinfix(row)
        ret.append([row["id"], row["navi"], infix, row["partOfSpeech"]])
    db.close()
    return ret

def getnavi(word):
    ret = []
    db = tornado.database.Connection("127.0.0.1", "navi", user="navi", password="navi")
    for row in db.query("""
    SELECT *
    FROM `metaWords`
    WHERE navi = ?"""
,word):
        infix = makeinfix(row)
        ret.append([row["id"],row["navi"], infix, row["partOfSpeech"]])
    db.close()
    return ret

def makeinfix(row):
    if row["partOfSpeech"] in (u"v.", u"vin.", u"vtr."):
        current = unicode(row["ipa"])
        current = current.replace(ur"ɛ",ur"e").replace(ur".",ur"").replace(ur"ɾ",ur"r") \
       .replace(ur"ɪ",ur"ì").replace(ur"ˈ",ur"").replace(ur"'",ur"x") \
       .replace(ur"ŋ",ur"ng").replace(ur"j",ur"y").replace(ur"ʔ",ur"'") \
       .replace(ur"æ",ur"ä").replace(ur"ˌ",ur"").replace(ur"\t{ts}",ur"ts") \
       .replace(ur"ṛ",ur"rr").replace(ur"ḷ",ur"ll").replace(ur"k̚",ur"k ") \
       .replace(ur"p̚",ur"p ").replace(ur"t̚",ur"t ").replace(ur"'̚",ur"' ") \
       .replace(u"\\",ur"").replace(ur"(",ur"").replace(ur")",ur"") \
       .replace(ur"[",ur"").replace(ur"]",ur"").replace(ur"  "," ") \
       .strip()
        current = re.sub(ur" or.*","",current)
        current = re.sub(ur"z(.*)engk(.*)e",ur"z\1enk\2e",current)
        current = re.sub(ur"t(.*)ì(m|n)\ ",ur"t\1ìng ",current)
        current = current.split(ur"$cdot$")
        if len(current) == 3:
            current = current[0] + u"<0><1>" + current[1] + u"<2>" + current[2]
        elif len(current) == 2:
            current = current[0] + u"<0><1><2>" + current[1]
        else:
            current = u"<0><1><2>" + current[0]
    else:
        current = unicode(row["navi"])
    return current

#def gettrans(id, cod):
    #ret = []
    #if cod not in (u"est",u"ptbr",u"de",u"eng",u"all"):
        #return ret
    #db = tornado.database.Connection("127.0.0.1", "navi", user="navi", password="navi")
    #if cod == "all":
            #for row in db.query("""
            #SELECT *
            #FROM `metaWords`
            #WHERE id = ?""",idd):
                #infix = makeinfix(row)
            #ret.append([row["id"],row["navi"], infix, row["partOfSpeech"]])
    #db.close()