def _(tree, params, rest): val = translate(tree, rest) if isinstance(val, FiVP): valverb = val.verb val.verb = FiA([ FiP(fi_verb, verbflags), compgen(valverb) if compgen else niTree(valverb, compflags) ]) val.flags |= phraseflags return val else: return FiA([ FiP(fi_verb, verbflags), compgen(val) if compgen else niTree(val, compflags) ])
def _(tree, params, rest): val = translateRestToArray(tree) obj = translate(params["obj"], obj_rules) return FiVP(verb=FiP(verb, {"verbi"}), obj=obj, objcase=object_case, subtrees=val)
def _(tree, params, rest): val = translateRest(tree) val2 = translate(params["subtree"], VP_RULES) subj = translate(params["subj"], NP_RULES) return FiVP(verb=FiA([FiP("olla"), niTree(val2, {"-tava"}), val]), subj=subj, flags={"nollapersoona"})
def _(tree, params, rest): val = translateRest(tree) subj = translate(params["subj"], NP_RULES) place = translate(params["obj"], NP_RULES) case = handleAccusative(place) return FiVP(verb=FiP(verb, {"verbi"}), subj=subj, subtrees=[niTree(place, {case}), val])
def _(tree, params, rest): val = translate(tree, rest) val2 = translate(params["subtree"], NP_RULES) pp = niTree(val2, {case}) verbp = FiP(verb, {"verbi", "-va"}) if verb else FiNI("") if after: return FiA([val, verbp, fi_pre_val, pp, fi_post_val], val.flags) return FiA([fi_pre_val, pp, fi_post_val, verbp, val], val.flags)
def _(tree, params, rest): val = translate(tree, rest) if fi_determiner: return FiA([FiP(fi_determiner, det_flags or set()), val], val.flags | (flags or set())) elif flags: return FiA([val], val.flags | flags) else: return val
def _(tree, params, rest): val = translateRest(tree) subj = translate(params["subj"], NP_RULES) place = translate(params["subtree"], NP_RULES) return FiVP( verb=FiP(verb or "olla"), subj=subj, subtrees=[ FiA([fi_pre_val, niTree(place, {case}), fi_post_val]), val ])
class TranslationPair(NamedTuple): enlemma: str filemma: str data: Any with open("fiwn.txt", "r") as file: for i, line in enumerate(file): print("\r"+str(i), end="") ficode, filemma, encode, enlemma, rel = line.strip().split("\t")[:5] pos = ficode[:4] if rel == "synonym" and pos in trans: if enlemma not in trans[pos]: trans[pos][enlemma] = [] words = [FiP(word) for word in filemma.split(" ")] if pos == "fi:v": for i, word in enumerate(words[1:]): if word.word in OBJECT_CASES: words.pop(i+1) objcase = OBJECT_CASES[word.word] break else: objcase = "akkusatiivi" data = (words[0], words[1:], objcase) else: data = FiA(words) trans[pos][enlemma].append(TranslationPair(enlemma=enlemma, filemma=filemma, data=data))
def _(tree, params, rest): val = translateRest(tree) return FiA([FiP(fi_adv), val], flags)
def _(tree, params, rest): val = translateRest(tree) return FiA([FiP(fi_adj, {"adjektiivi"} | (flags or set())), val])
def _(tree, params, rest): val = translateRest(tree) val2 = translate(params["subtree"], VP_RULES) # TODO: predikatiivimuoto erikseen: kykenevä tekemään return FiA([niTree(val2, {"-minen", "illatiivi"}), FiP("kykenevä"), val])
def _(tree, params, rest): val = translateRest(tree) noun = FiP(tree["lemma"], {"monikko"}) return FiA([noun, val], noun.flags)
def _(tree, params, rest): val = translateRest(tree) noun = FiP(fi_noun) return FiA([noun, val], noun.flags)
def _(tree, params, rest): val = translateRestToArray(tree) return FiVP(verb=FiP(verb, {"verbi"}), subtrees=val)
def _(tree, params, rest): val = translateRestToArray(tree) subj = translate(params["subj"], NP_RULES) return FiVP(verb=FiP(verb, {"verbi"}), subj=subj, subtrees=val)
def _(tree, params, rest): val = translateRest(tree) val2 = translate(params["subtree"], VP_RULES) return FiA([FiP("olla"), niTree(val2, {"-tava"}), val])