/webapp/templates/parse2.html |
---|
0,0 → 1,20 |
{% extends "base.html" %} |
{% block title %}Number parser{% end %} |
{% block body %} |
<b>Na'vi word:</b><br /> |
<form action="/parse" method="post"> |
<input id="word" name="word" type="text" value="{{last}}" style="width: 100%;" /> |
<input name="btn" type="submit" value="Parse!" /> |
</form> |
{% if type(out) == list %} |
{{ out[0][1]}} <br /> |
{{ out[1]}} <br /> |
{{ out[2]}} <br /> |
{{ out[3]}} |
{% end %} |
<script type="text/javascript"> |
document.getElementById("word").focus(); |
</script> |
{% end %} |
/webapp/templates/parse.html |
---|
0,0 → 1,20 |
{% extends "base.html" %} |
{% block title %}Number parser{% end %} |
{% block body %} |
<b>Na'vi word:</b><br /> |
<form action="/parse" method="post"> |
<input id="word" name="word" type="text" value="{{last}}" style="width: 100%;" /> |
<input name="btn" type="submit" value="Parse!" /> |
</form> |
{% if type(out) == list %} |
{{ out[0]}} <br /> |
{{ out[1]}} <br /> |
{{ out[2]}} <br /> |
{{ out[3]}} |
{% end %} |
<script type="text/javascript"> |
document.getElementById("word").focus(); |
</script> |
{% end %} |
/webapp/templates/base.html |
---|
1,6 → 1,6 |
<html> |
<head> |
<title>{% block title %}Title{% end %}</title> |
<title>Tsim Apiak - {% block title %}Title{% end %}</title> |
<style type="text/css"> |
body { |
background: #145179; |
14,6 → 14,10 |
text-align: center; |
font-size: 52px; |
} |
h2 { |
text-align: center; |
font-size: 24px; |
} |
#center { |
background: #2594DE; |
width: 760px; |
25,7 → 29,8 |
</head> |
<body> |
<div id="center"> |
<h1>{% block title %}Title{% end %}</h1> |
<h1>Tsim Apiak</h1> |
<h2>{% block title %}Title{% end %}</h2> |
{% block body %}Body{% end %} |
</div> |
</body> |
/webapp/templates/number.html |
---|
1,6 → 1,6 |
{% extends "base.html" %} |
{% block title %}Na'vi number translator{% end %} |
{% block title %}Number translator{% end %} |
{% block body %} |
<b>Na'vi number:</b><br /> |
/webapp/main.py |
---|
5,11 → 5,14 |
import tornado.ioloop |
import tornado.web |
import tornado.autoreload |
import tornado.database |
import os |
import re |
from navi.parsenum import parse |
from tsimapiak import parsenum |
from tsimapiak import dbconnector |
from tsimapiak import parse |
from tsimapiak import parse2 |
class Index(tornado.web.RequestHandler): |
def get(self): |
24,7 → 27,7 |
num = self.get_argument("num").strip() |
except: |
self.redirect("/number") |
numout = parse(num.replace(" ","")) |
numout = parsenum.parse(num.replace(" ","")) |
if numout == None: |
numout = -1 |
self.render("templates/number.html", last=num, numout=numout) |
33,19 → 36,45 |
def get(self): |
os.system("/usr/bin/restartnavi") |
class TestDB(tornado.web.RequestHandler): |
def get(self): |
text = "" |
db = tornado.database.Connection("127.0.0.1", "navi", user="navi", password="navi") |
for thing in db.query("SELECT * FROM test"): |
text = "<br />".join((text, str(thing.id) + " - " + thing.asd)) |
lis = dbconnector.getnavilist() |
text = u"id | navi | infix | partofspeech<br />" |
text += u"<br />".join(u" | ".join(unicode(y) for y in x) for x in lis) |
self.write(text) |
class Parse(tornado.web.RequestHandler): |
def get(self): |
self.render("templates/parse.html", last="", out=None) |
def post(self): |
try: |
word = self.get_argument("word").strip() |
except: |
self.redirect("/parse") |
out = parse.parsefix(word) |
self.render("templates/parse.html", last=word, out=out) |
class Parse2(tornado.web.RequestHandler): |
def get(self): |
self.render("templates/parse2.html", last="", out=None) |
def post(self): |
try: |
word = self.get_argument("word").strip() |
except: |
self.redirect("/parse2") |
out = parse2.parseword(word) |
self.render("templates/parse2.html", last=word, out=out) |
application = tornado.web.Application([ |
("/", Index), |
("/number", Number), |
("/restart", Restart), |
("/testdb", TestDB) |
("/testdb", TestDB), |
("/parse", Parse), |
("/parse2", Parse2) |
]) |
if __name__ == "__main__": |
/tsimapiak/parse2.py |
---|
0,0 → 1,23 |
#!/usr/bin/python |
# -*- coding: utf-8 -*- |
import re |
import dbconnector |
infixes0 = ur"(?P<in0>(?:awn|eyk|us|äp)?)" |
infixes1 = ur"(?P<in1>(?:ìyev|iyev|ìmìy|arm|asy|ilv|ìmv|imv|ìrm|irv|ìsy|aly|ary|ìly|ìry|ìlm|alm|am|ay|er|ìm|iv|ìy|ol)?)" |
infixes2 = ur"(?P<in2>(?:äng|ats|eiy|ei|uy)?)" |
#prefixesn = ur"(?P<pre>(?:(?:fì|tsa)?(?:me|pxe|ay|fra)?|(?:fay)?|(?:tsay)?)(?:fne)?(?:tì|sä)?" |
def parseword(wordin): |
wordfound = [0, u"", u"", u""] |
wordre = None |
ret = [wordfound, u"", u"", u""] |
for word in dbconnector.getnavilist(): |
wordre = u" ".join(ur"(?:.*)" + x + ur"(?:.*)" for x in word[2].split(u" ")).replace(u"<0><1>", infixes0 + infixes1).replace(u"<2>",infixes2) |
rem = re.match(wordre,wordin) |
if rem: |
wordfound = word |
ret = [wordfound, rem.group("in0"), rem.group("in1"), rem.group("in2")] |
break |
return ret |
/tsimapiak/parse.py |
---|
0,0 → 1,86 |
#!/usr/bin/python |
# -*- coding: utf-8 -*- |
import re |
from dbconnector import getnavilist |
wordlist = getnavilist() |
infixes0 = [ u"awn", u"eyk", u"us", u"äp" ] |
infixes1 = [ u"ìyev", u"iyev", u"ìmìy", u"arm", u"asy", u"ilv", u"ìmv", u"imv" u"ìrm", u"irv", u"ìsy", u"aly", u"ary", u"ìly", u"ìry", u"ìlm", u"alm", u"am", u"ay", u"er", u"ìm", u"iv", u"ìy", u"ol" ] |
infixes2 = [ u"äng", u"ats", u"eiy", u"ei", u"uy" ] |
# Returns array with Word,Infix 0,Infix 1,Infix 2,Case,Gender,Number suffixes,Inclusive,Indefinite,Vocative (suffix),Plural,Adposition,Adject pre,Adject suff,am/ay/tu/vi/yu,adverbial,nominalise,sä,fne,lenited? |
def parsefix(original): |
realword = u"" |
infix0 = u"" |
infix1 = u"" |
infix2 = u"" |
infix01 = u"" |
infix_1 = u"" |
infix_2 = u"" |
for eachword in wordlist: |
regex = re.sub(u" ",u"[^ ]* [^ ]*",eachword[2]) |
regex = re.sub(u"^",u"[^ ]*",regex) |
regex = re.sub(u"$",u"[^ ]*",regex) |
regex = re.sub(u"<0><1>",u"[^ ]*",regex) |
regex = re.sub(u"<2>",u"[^ ]*",regex) |
if re.match(regex,original): |
realword = eachword[2] |
break |
if realword == u"": |
return [u"[" + original + u"]",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u""] |
else: |
if re.search(u"<",realword): |
beginning = re.sub(u"<0><1>.*",u"",realword) |
middle = re.sub(u".*<0><1>(.*)<2>.*",ur"\1",realword) |
end = re.sub(u".*<2>",u"",realword) |
infix01 = re.sub(u".*?" + re.sub(u"<0><1>",u"([^ ]*)",re.sub(u"<2>",u"[^ ]*",realword)) + u".*?",ur"\1",original) |
infix_2 = re.sub(u".*?" + re.sub(u"<2>",u"([^ ]*)",re.sub(u"<0><1>",u"[^ ]*",realword)) + u".*?",ur"\1",original) |
for eachinfix in infixes0: |
if infix01.startswith(eachinfix): |
infix0 = eachinfix |
infix_1 = infix01[len(eachinfix):] |
break |
else: |
infix0 = u"" |
infix_1 = infix01 |
gotinfix1 = False |
for eachinfix in infixes1: |
if infix_1.startswith(eachinfix): |
infix1 = eachinfix |
infix_1 = infix_1[len(eachinfix):] |
if infix_1 != u"": |
if re.search(u"<0><1><2>",realword): |
infix_2 = infix_1 |
else: |
return [u"[" + original + u"]",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u""] |
gotinfix1 = True |
break |
if gotinfix1 == False: |
if re.search(u"<0><1><2>",realword): |
if infix_1 == u"": |
infix_2 = infix_1 |
infix1 = u"" |
elif infix_1 == u"": |
infix1 = u"" |
else: |
return [u"[" + original + u"]",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u""] |
gotinfix2 = False |
for eachinfix in infixes2: |
if infix_2.startswith(eachinfix): |
infix2 = infix_2[:len(eachinfix)] |
infix_2 = infix_2[len(eachinfix) - 1:] |
gotinfix2 = True |
break |
if gotinfix2 == False or infix_2 != u"": |
if infix_2.startswith(end): |
suffixes = infix2[len(end) - 1:] + end |
elif infix_2 == u"": |
infix2 = u"" |
else: |
return [u"[" + original + u"]",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u""] |
# print u"0" + unicode(infix0) + u" 1" + unicode(infix1) + u" 2" + unicode(infix2) |
return [realword,infix0,infix1,infix2,u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u""] |
else: |
return [realword,u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u"",u""] |
/tsimapiak/dbconnector.py |
---|
0,0 → 1,70 |
#!/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() |