Subversion Repositories navi

Rev

Rev 298 | 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 -*-
176 muzer 3
#    This file is part of Tsim Apiak.
4
#
5
#    Tsim Apiak is free software: you can redistribute it and/or modify
6
#    it under the terms of the GNU General Public Licence as published by
7
#    the Free Software Foundation, either version 3 of the Licence, or
8
#    (at your option) any later version.
9
#
10
#    In addition to this, you must also comply with clause 4 of the
11
#    Apache Licence, version 2.0, concerning attribution. Where there
12
#    is a contradiction between the two licences, the GPL
13
#    takes preference.
14
#
186 szabot 15
#    Tsim Apiak is distributed in the hope that it will be useful,
176 muzer 16
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
#    GNU General Public License for more details.
19
#
20
#    You should have received a copy of the GNU General Public License
21
#    along with Tsim Apiak.  If not, see <http://www.gnu.org/licenses/>.
46 szabot 22
 
176 muzer 23
 
283 muzer 24
import mysql.connector as mysql
46 szabot 25
 
26
def getnavilist():
27
    ret = []
283 muzer 28
    db = mysql.connect(host="127.0.0.1", db="navi", user="navi", passwd="navi")
29
    cur = db.cursor(dictionary=True)
30
    cur.execute("""
103 szabot 31
    SELECT *
46 szabot 32
    FROM `metaWords`
275 muzer 33
    WHERE partOfSpeech <> 'num.' AND partOfSpeech <> 'prefix' AND partOfSpeech <> 'affix'
283 muzer 34
    ORDER BY CHAR_LENGTH(navi) DESC""")
35
    for row in cur:
298 muzer 36
        navi = row["navi"].replace("+", "").replace("-", "")
284 muzer 37
        if row["infixes"] and row["infixes"] != "NULL": # yeah seriously
298 muzer 38
            ret.append({"id": row["id"], "navi": navi, "orig_navi": navi, "infix": row["infixes"].lower(), "type": row["partOfSpeech"], "lenited": False})
65 szabot 39
        else:
298 muzer 40
            ret.append({"id": row["id"], "navi": navi, "orig_navi": navi, "infix": navi.lower(), "type": row["partOfSpeech"], "lenited": False})
283 muzer 41
    cur.close()
46 szabot 42
    db.close()
43
    return ret
44
 
283 muzer 45
def getaffixlists():
46
    ret = ([], [], [])
47
    db = mysql.connect(host="127.0.0.1", db="navi", user="navi", passwd="navi")
48
    cur = db.cursor(dictionary=True)
49
    cur.execute("""
50
    SELECT *
51
    FROM `metaInfixes`
52
    ORDER BY CHAR_LENGTH(navi) DESC""")
53
    for row in cur:
287 muzer 54
        endfix = False
283 muzer 55
        if row["navi"] and row["navi"][0] == "-":
298 muzer 56
            navi = row["navi"].replace("-", "").lower()
57
            ret[2].append({"id": row["id"], "navi": navi, "orig_navi": navi, "gloss": row["shorthand"].upper()})
287 muzer 58
            endfix = True
59
        if row["navi"] and row["navi"][-1] in ("-", "+"):
298 muzer 60
            navi = row["navi"].replace("-", "").replace("+", "").lower()
61
            ret[0].append({"id": row["id"], "navi": navi, "orig_navi": navi, "gloss": row["shorthand"].upper()})
287 muzer 62
            endfix = True
63
        if not endfix:
299 muzer 64
            if row["position"] is None or row["position"] == "NULL":
283 muzer 65
                # not actually an affix
66
                continue
298 muzer 67
            ret[1].append({"id": row["id"], "navi": row["navi"].lower(), "orig_navi": row["navi"].lower(), "gloss": row["shorthand"].upper(), "position": int(row["position"])})
283 muzer 68
    cur.close()
69
    db.close()
288 muzer 70
 
71
    for subret in ret:
72
        subret.sort(key=lambda x: len(x["navi"]), reverse=True)
73
 
283 muzer 74
    return ret
75
 
246 szabot 76
def translate(wid, language):
235 muzer 77
    ret = None
283 muzer 78
    db = mysql.connect(host="127.0.0.1", db="navi", user="navi", passwd="navi")
79
    cur = db.cursor(dictionary=True)
80
    cur.execute("""
136 muzer 81
    SELECT *
82
    FROM `localizedWords`
283 muzer 83
    WHERE id = %s AND languageCode = %s""", (wid, language))
84
    for row in cur:
136 muzer 85
        ret = row["localized"]
139 szabot 86
        break
235 muzer 87
    if ret == None:
88
        return u"ERROR: WORD NOT LOCALISED"
136 muzer 89
    db.close()
176 muzer 90
    return ret