Subversion Repositories navi

Rev

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

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

import re
import dbconnector

wordlist = dbconnector.getnavilist()

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"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"]
postfixes = [u"-ä", u"an", u"e", u"ìl", u"ìri", u"it", u"l", u"lo", u"ng", u"o", u"ri", u"ru", u"t", u"ti", u"ur", u"ve", u"y", u"yä", u"eyä", u"ya", u"tu", u"vi", u"yu"]
#prefixesn = ur"(?P<npr>(?:(?:fì|tsa)?(?:me|pxe|ay|fra)?|(?:fay)?|(?:tsay)?)(?:fne)?(?:tì|sä)?"
#prefixesv = ur"(?P<vpr>(?:nì|sä|tì|rä'ä |ke )?)"

def parseword(wordin):
    ret = {"word": {"id": 0, "navi": u" ".join(wordin), "infix": u"", "type": u""}}
    for word in wordlist:
        foundit = True
        foundprefs = []
        foundposts = []
        splitword = word["infix"].split(u" ")
        if len(wordin) < len(splitword):
            foundit = False
            next
        for wor in range(len(splitword)):
            if not foundit:
                break
            foundprefs.append([])
            foundposts.append([])
            center = u""
            foundins = [u"", u"", u""]
            pre = []
            post = []
            if u"<1>" in splitword[wor]:
                for in1 in infixes1:
                    for in2 in infixes2:
                        for in3 in infixes3:
                            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]
                                break
                        if center != u"": break
                    if center != u"": break
            else:
                if splitword[wor] in wordin[wor]:
                    center = splitword[wor]
            if center == u"":
                foundit = False
                break
            pref, posf = wordin[wor].split(center)
            for pre in prefixes:
                if pref.endswith(pre):
                    foundprefs[wor].append(pre)
                    pref = pref[:-len(pre)]
            if pref != u"":
                foundit = False
                break
            for pos in postfixes:
                if posf.beginswith(pos):
                    foundposts[wor].append(pos)
                    posf = posf[len(pos):]
            if posff != u"":
                foundit = False
                break
        if foundit == True:
            foundword = word
            break
    if foundit == True:
        ret["pref"] = foundprefs
        ret["post"] = foundposts
        ret["inf"] = foundins
        ret["word"] = foundword
    return ret

def parsesent(sent):
    ret = []
    left = len(sent)
    while left:
        word = parseword(sent[-left:])
        left -= len(word["word"]["navi"].split(" "))
        ret.append(word)
    return ret