2,37 → 2,31 |
# -*- coding: utf-8 -*- |
|
import re |
#import dbconnector |
import dbconnector |
|
wordlist = dbconnector.getnavilist() |
|
#wordlist = [{"id": 1, "navi": u"si", "infix": u"s<1><2><3>i", "type": u"v."}, |
#{"id": 2, "navi": u"wou", "infix": u"w<1><2>o<3>u", "type": u"v."}, |
#{"id": 3, "navi": u"kame", "infix": u"k<1><2>am<3>e", "type": u"v."}, |
#{"id": 4, "navi": u"tìng", "infix": u"t<1><2><3>ìng", "type": u"v."}, |
#{"id": 5, "navi": u"yerik", "infix": u"yerik", "type": u"n."}, |
#{"id": 6, "navi": u"nari", "infix": u"nari", "type": u"n."}] |
|
infixes1 = [u"awn", u"eyk", u"us", u"äp", u""] |
infixes2 = [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", u""] |
infixes3 = [u"äng", u"ats", u"eiy", u"ei", u"uy", u""] |
prefixes = [u"tsay", u"fay", u"tsa", u"fra", u"pxe", u"ay", u"me", u"pe", u"le", u"nì", u"sä", u"tì", u"ke", u"fì", u"a"] |
postfixes = [u"eyä", u"ìri", u"an", u"ìl", u"it", u"lo", u"ng", u"ri", u"ru", u"ti", u"ur", u"ve", u"yä", u"ya", u"tu", u"vi", u"yu", u"e", u"l", u"o", u"t", u"y", u"a", u"ä"] |
#prefixesn = ur"(?P<npr>(?:(?:fì|tsa)?(?:me|pxe|ay|fra)?|(?:fay)?|(?:tsay)?)(?:fne)?(?:tì|sä)?" |
prefixes = [u"ay", u"me", u"pxe", u"pe", u"a", u"le", u"nì", u"sä", u"tì", u"ke", u"fì", u"fay", u"tsa", u"tsay", u"fra"] |
#postfixesv = ur"(?P<vpr>(?:nì|sä|tì|rä'ä |ke )?)" |
#prefixesv = ur"(?P<vpr>(?:nì|sä|tì|rä'ä |ke )?)" |
|
def parseword(wordin): |
if type(wordin) == type(u"x"): |
wordin = wordin.split(" ") |
ret = {"word": {"id": 0, "navi": u" ".join(wordin), "infix": u"", "type": u""}} |
foundword = u"" |
ret = {"word": {"id": 0, "navi": u"[" + u" ".wordin[0] + u"]", "infix": u"", "type": u""}} |
for word in wordlist: |
foundit = True |
foundprefs = [] |
foundposts = [] |
splitword = word["infix"].split(" ") |
if len(wordin) != len(splitword): next |
splitword = word["infix"].split(u" ") |
if len(wordin) < len(splitword): |
foundit = False |
next |
for wor in range(len(splitword)): |
foundinf = False |
if not foundit: |
break |
foundprefs.append([]) |
foundposts.append([]) |
center = u"" |
39,7 → 33,6 |
foundins = [u"", u"", u""] |
pre = [] |
post = [] |
found = False |
if u"<1>" in splitword[wor]: |
for in1 in infixes1: |
for in2 in infixes2: |
47,41 → 40,49 |
if splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3) in wordin[wor]: |
center = splitword[wor].replace(u"<1><2>",in1+in2).replace(u"<3>",in3) |
foundins = [in1, in2, in3] |
foundinf = True |
break |
if foundinf: break |
if foundinf: break |
if center != u"": break |
if center != u"": break |
else: |
if splitword[wor] in wordin[wor]: |
center = splitword[wor] |
foundinf = True |
if not foundinf: |
if center == u"": |
foundit = False |
break |
pref, posf = wordin[wor].replace(center,u" ").split(" ") |
pref, posf = wordin[wor].split(center) |
for pre in prefixes: |
if pref.endswith(pre): |
foundprefs[wor].append(pre) |
pref = pref[:len(pref)-len(pre)] |
pref = pref[:-len(pre)] |
if pref != u"": |
foundit = False |
break |
foundposts[wor] = posf |
for pos in postfixes: |
if posf.startswith(pos): |
foundposts[wor].append(pos) |
posf = posf[len(pos):] |
if posf != u"": |
foundit = False |
break |
if foundit == True: |
foundword = word |
break |
if foundit == True: |
ret["pref"] = foundprefs |
ret["post"] = foundposts |
ret["inf"] = foundins |
if foundit == True: |
ret["word"] = foundword |
return ret |
|
#print(parseword([u"tìtìng"])) |
#print(parseword([u"keykame"])) |
#print(parseword([u"kameie"])) |
#print(parseword([u"tìsusiti"])) |
#print(parseword([u"weykayoeiu"])) |
#print(parseword([u"yerikit"])) |
#print(parseword([u"menari"])) |
#print(parseword([u"menariri"])) |
def parsesent(sent): |
sent = sent.strip().lower() |
sent = re.sub(ur"[^\w ]",u"",sent) |
sent = re.sub(ur"\ +",u" ",sent) |
sent = sent.split(u" ") |
ret = [] |
left = len(sent) |
while left: |
word = parseword(sent[-left:]) |
left -= len(word["word"]["navi"].split(" ")) |
ret.append(word) |
return ret |