def translateUnknownPos(tree): if settings.debug_mode: print(" " * translate_indent + "translateUnknownPos(" + tree["POS_coarse"] + ":" + tree["word"] + "): ", end="") if tree["POS_coarse"] == "ADJ": return translate(tree, AP_RULES) elif tree["POS_coarse"] == "ADV" or tree["arc"] == "npadvmod": return translate(tree, ADVP_RULES) elif tree["POS_coarse"] == "NOUN": return translate(tree, NP_RULES) elif tree["POS_coarse"] == "NUM": return translate(tree, NP_RULES) elif tree["POS_coarse"] == "VERB": return translate(tree, VP_RULES) elif tree["POS_coarse"] == "ADP": return translate(tree, PP_RULES) elif tree["POS_coarse"] == "PUNCT": if tree["word"] in ['"', "'", ":", "!", "?"]: return FiNI(tree["word"]) else: return FiNI("") else: return FiNI("[" + treeToStr(tree) + "]")
def _(tree, params, rest): val = translate(tree, rest) val2 = translate(params["subtree"], PHRASE_RULES) return FiA( [val, FiNI("("), FiNI(fi_conj), niTree(val2), FiNI(")")], val.flags)
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 translate(tree, rules): global translate_indent translate_indent += 1 if settings.debug_mode: print(translate_indent * " " + "translate(" + tree["word"] + ", ", end="") if rules == AP_RULES: print("AP_RULES)", end="") elif rules == ADVP_RULES: print("ADVP_RULES)", end="") elif rules == NP_RULES: print("NP_RULES)", end="") elif rules == VP_RULES: print("VP_RULES)", end="") elif rules == PP_RULES: print("PP_RULES)", end="") elif rules == PHRASE_RULES: print("PHRASE_RULES)", end="") else: print("<rules#" + str(len(rules)) + ">)", end="") for i, rule in enumerate(rules): ctree = copy.deepcopy(tree) m, d = rule.matches(ctree) if m: if settings.debug_mode: print(" -> match " + treeToCode(rule.pattern)) ans = rule.translate(ctree, d, rules[i:]) translate_indent -= 1 return ans if settings.debug_mode: print(" -> no match") translate_indent -= 1 return FiNI("[" + treeToStr(tree) + "]")
def _(tree, params, rest): val = translate(tree, rest) return FiA([FiNI(fi_pronoun), val], val.flags | flags)
def _(tree, params, rest): val = translate(tree, rest) return FiA([FiNI("kuinka"), val], val.flags)
def _(tree, params, rest): val = translate(tree, rest) val2 = translate(params["cc"], cc_rules) return FiA([val, FiNI(fi_conj), val2], val.flags)
def _(tree, params, rest): val = translateRest(tree) val2 = translate(params["subtree"], NP_RULES) return FiA([val, FiNI("kuin"), niTree(val2, {"nominatiivi"})], val.flags)
def _(tree, params, rest): val = translateRest(tree) val2 = translateUnknownPos(params["subtree"]) return FiA([val, FiNI("toisin kuten"), val2])
def _(tree, params, rest): val = translateRest(tree) val2 = translate(params["subtree"], NP_RULES) return FiA([niTree(val2, {"genetiivi"}), FiNI("toimesta"), val])
val = translate(tree, rest) val2 = translate(params["proper"], NP_RULES) return FiA([niTree(val2, {"genetiivi"}), val], val.flags) def prepositionToCase(preposition, case, verb=None, fi_preposition=None, fi_postposition=None, after=False, pp_rule=True, np_rule=True, ap_rule=True, vp_rule=True): fi_pre_val = FiNI(fi_preposition or "") fi_post_val = FiNI(fi_postposition or "") if pp_rule: @match( PP_RULES, { "word": preposition, "POS_fine": "IN", "modifiers": [{ "_name": "subtree", "_del": True, "POS_coarse": {"NOUN", "PROPN", "PRON", "NUM"} }] })