/webapp/main.py |
---|
0,0 → 1,88 |
#!/usr/bin/python |
# -*- coding: utf-8 -*- |
import tornado.httpserver |
import tornado.ioloop |
import tornado.web |
import tornado.autoreload |
import tornado.database |
import os |
import re |
from tsimapiak.parsenum import parse |
class Index(tornado.web.RequestHandler): |
def get(self): |
self.redirect("/number") |
class Number(tornado.web.RequestHandler): |
def get(self): |
self.render("templates/number.html", last="", numout=None) |
def post(self): |
try: |
num = self.get_argument("num").strip() |
except: |
self.redirect("/number") |
numout = parse(num.replace(" ","")) |
if numout == None: |
numout = -1 |
self.render("templates/number.html", last=num, numout=numout) |
class Restart(tornado.web.RequestHandler): |
def get(self): |
os.system("/usr/bin/restartnavi") |
def getwords(): |
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"""): |
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"]) |
ret.append([row["id"], row["navi"], current, row["partOfSpeech"]]) |
return ret |
class TestDB(tornado.web.RequestHandler): |
def get(self): |
lis = getwords() |
text = u"<br />".join([u"\t".join(unicode(x)) for x in lis]) |
self.write(text) |
application = tornado.web.Application([ |
("/", Index), |
("/number", Number), |
("/restart", Restart), |
("/testdb", TestDB) |
]) |
if __name__ == "__main__": |
http_server = tornado.httpserver.HTTPServer(application) |
http_server.listen(1337) |
tornado.autoreload.start() |
tornado.ioloop.IOLoop.instance().start() |
/webapp/templates/base.html |
---|
0,0 → 1,37 |
<html> |
<head> |
<title>Tsim Apiak - {% block title %}Title{% end %}</title> |
<style type="text/css"> |
body { |
background: #145179; |
color: #FFF6D0; |
font-family: papyrus,"Georgia","Times New Roman",serif; |
padding: 0px; |
border: 0px; |
margin: 0px; |
} |
h1 { |
text-align: center; |
font-size: 52px; |
} |
h2 { |
text-align: center; |
font-size: 24px; |
} |
#center { |
background: #2594DE; |
width: 760px; |
margin-left: auto; |
margin-right: auto; |
padding: 20px; |
} |
</style> |
</head> |
<body> |
<div id="center"> |
<h1>Tsim Apiak</h1> |
<h2>{% block title %}Title{% end %}</h2> |
{% block body %}Body{% end %} |
</div> |
</body> |
</html> |
Property changes: |
Added: svn:executable |
## -0,0 +1 ## |
+* |
\ No newline at end of property |
Index: webapp/templates/number.html |
=================================================================== |
--- webapp/templates/number.html (nonexistent) |
+++ webapp/templates/number.html (revision 34) |
@@ -0,0 +1,20 @@ |
+{% extends "base.html" %} |
+ |
+{% block title %}Number translator{% end %} |
+ |
+{% block body %} |
+Na'vi number: |
+ |
+ |
+ |
+ |
+{% if type(numout) == tuple %} |
+Decimal: {{ numout[0] }} |
+Octal: {{ numout[1] }} |
+{% elif type(numout) == int %} |
+Not a valid number! |
+{% end %} |
+ |
+document.getElementById("num").focus(); |
+ |
+{% end %} |
/webapp/templates/number.html |
---|
Property changes: |
Added: svn:executable |
## -0,0 +1 ## |
+* |
\ No newline at end of property |
Index: webapp/README.txt |
=================================================================== |
--- webapp/README.txt (nonexistent) |
+++ webapp/README.txt (revision 34) |
@@ -0,0 +1,3 @@ |
+This is a webapp for TsimApiak written for the Tornado Web Server. |
+ |
+To use it you have to put the tsimapiak directory inside this dir, and run main.py. |
Index: tsimapiak/parsenum.py |
=================================================================== |
--- tsimapiak/parsenum.py (nonexistent) |
+++ tsimapiak/parsenum.py (revision 34) |
@@ -0,0 +1,81 @@ |
+#!/usr/bin/python |
+# -*- coding: utf-8 -*- |
+ |
+import re |
+ |
+num = [u"kew", |
+ u"'aw", |
+ u"mune", |
+ u"pxey", |
+ u"tsìng", |
+ u"mrr", |
+ u"pukap", |
+ u"kinä"] |
+ |
+rem = [u"aw", |
+ u"mun", |
+ u"pey", |
+ u"sìng", |
+ u"mrr", |
+ u"fu", |
+ u"hin"] |
+ |
+base = [u"", |
+ u"me", |
+ u"pxe", |
+ u"tsì", |
+ u"mrr", |
+ u"pu", |
+ u"ki"] |
+ |
+ |
+numre = \ |
+ u"^(?:(" + "|".join(base) + u")zazam??)?" + \ |
+ u"(?:(" + "|".join(base) + u")vozam??)?" + \ |
+ u"(?:(" + "|".join(base) + u")zam??)?" + \ |
+ u"(?:(" + "|".join(base) + u")vo(?:l(?=a|))?)?" + \ |
+ u"((?:" + "|".join(rem) + u")|" + \ |
+ u"(?:" + "|".join(num) + u"))?$" |
+numre = re.compile(numre) |
+ |
+def parse(numin): |
+ if type(numin) != unicode: |
+ return None |
+ if numin == u"": |
+ return None |
+ numin = numin.replace(u"í",u"ì").replace(u"á",u"ä") |
+ try: |
+ mat = numre.match(numin).groups() |
+ except: |
+ return None |
+ numout = 0 |
+ numoct = 0 |
+ try: |
+ numout += rem.index(mat[4]) + 1 |
+ numoct += rem.index(mat[4]) + 1 |
+ except: |
+ try: |
+ numout += num.index(mat[4]) |
+ numoct += num.index(mat[4]) |
+ except: pass |
+ try: |
+ numout += (base.index(mat[3]) + 1) * 8 |
+ numoct += (base.index(mat[3]) + 1) * 10 |
+ except: pass |
+ try: |
+ numout += (base.index(mat[2]) + 1) * 8**2 |
+ numoct += (base.index(mat[2]) + 1) * 10**2 |
+ except: pass |
+ try: |
+ numout += (base.index(mat[1]) + 1) * 8**3 |
+ numoct += (base.index(mat[1]) + 1) * 10**3 |
+ except: pass |
+ try: |
+ numout += (base.index(mat[0]) + 1) * 8**4 |
+ numoct += (base.index(mat[0]) + 1) * 10**4 |
+ except: pass |
+ return numout, numoct |
+ |
+ |
+if __name__ == "__main__": |
+ print parse(u"mrrvolaw") |
/tsimapiak/parsenum.py |
---|
Property changes: |
Added: svn:executable |
## -0,0 +1 ## |
+* |
\ No newline at end of property |
Index: tsimapiak/__init__.py |
=================================================================== |