"""Tests against Armbruster's hand-marked Amharic verb tables. Expected answers are Armbruster forms, written with U+135F ETHIOPIC COMBINING GEMINATION MARK after each doubled consonant, taken from github.com/geezorg/data, amharic/verbs/ArmbrusterVerbs-Geminated-20081118.txt. The offline tests need nothing but this directory: each case carries the seg that HornMorpho 5.3.6 returns for the reading. The live tests run HornMorpho itself and are skipped when it is not installed. python test_gemination.py (or: pytest test_gemination.py) """ import gemination as G # (word, Armbruster form, seg of the matching reading from hm.anal('a', word, degem=False), sources) CASES = [ ("ጨምሮ", "ጨም፟ሮ", "----<ጨ/ምር>ኦ------", ["root"]), ("ተከትሎ", "ተከት፟ሎ", "----<ተ-ከ/ትል>ኦ------", ["root"]), ("ወሳኝ", "ወሳ፟ኝ", "-<ወ/ሳን-ኢ>------", ["root"]), ("መከበር", "መከ፟በር", "-<መ/-ከበር>------", ["t-prefix"]), ("ይገኛል", "ይገ፟ኛ፟ል", "----ይ---ኣ/ል---", ["t-prefix", "root"]), ("ይደረጋል", "ይደ፟ረ፟ጋል", "----ይ---ኣ/ል---", ["t-prefix", "root"]), ("ገለባበጠ", "ገለባበ፟ጠ", "----<ገለባ/በጥ>አ------", ["reduplication"]), ("ይቀላቀላል", "ይቀ፟ላቀ፟ላል", "----ይ---ኣ/ል---", ["t-prefix", "reduplication"]), ] # Homographs: the spelling has several readings; Armbruster's form must be one of them. HOMOGRAPHS = [ ("መለወጥ", "መለ፟ወጥ", [[1], [2]]), # passive mälläwäṭ, active mäläwwäṭ ("ይገባል", "ይገ፟ባ፟ል", [[], [1, 2]]), # active yɨgäbal, passive yɨggäbbal ] def positions(marked): """Armbruster form -> 0-based indices of geminated characters.""" out, n = [], 0 for ch in marked: if ch == G.GEM_MARK: out.append(n - 1) else: n += 1 return out def test_mark_roundtrip(): for word, arm, _, _ in CASES: assert G.mark(word, positions(arm)) == arm def test_offline_segs(): for word, arm, seg, sources in CASES: g = G.reading_gemination(word, {"seg": seg}) assert g["ok"], word assert g["pos"] == positions(arm), (word, g["pos"], arm) assert g["sources"] == sources, (word, g["sources"]) def test_suffix_final_geminate_dropped(): # the -all of ይገኛል is geminate in the seg but inaudible word-finally g = G.reading_gemination("ይገኛል", {"seg": "----ይ---ኣ/ል---"}, final="keep") assert g["pos"] == [1, 2, 3] def _hm(): try: import hm # noqa: F401 return True except Exception: return False def test_live_hornmorpho(): if not _hm(): print("HornMorpho not installed: live test skipped") return for word, arm, _, sources in CASES: pats = G.analyze(word) assert pats and pats[0]["pos"] == positions(arm), (word, [p["pos"] for p in pats], arm) assert pats[0]["sources"] == sources, (word, pats[0]["sources"]) for word, arm, expected in HOMOGRAPHS: got = sorted(p["pos"] for p in G.analyze(word)) assert got == sorted(expected), (word, got) assert positions(arm) in got # v3 rules: (word, expected form, seg HornMorpho 5.3.6 returns, rule that must fire) V3_CASES = [ ("ማሳደግ", "ማሳደ፟ግ", "-<ማስ-ኣደግ>------", "causative_glottal"), # Armbruster ማሳደ፟ግ ("አሳይቷል", "አሳይ፟ቷል", "----<ኣስ-ኣይት>ኦ---ኣ/ል---", "causative_glottal"), # Armbruster አሳይ፟ቷል ("አስታውሶ", "አስታው፟ሶ", "----<ኣስተ-ኣውስ>ኦ------", "causative_glottal"), # Armbruster አስታው፟ሶ ("የሚጠበቅ", "የሚጠ፟በ፟ቅ", "የ--/ም--ይ------", "relative_m_light"), # native listener ] def test_v3_rules(): for word, form, seg, rule in V3_CASES: g = G.reading_gemination(word, {"seg": seg}) assert G.mark(word, g["pos"]) == form, (word, G.mark(word, g["pos"]), form) assert rule in g["rules"], (word, g["rules"]) assert G.reading_gemination(word, {"seg": seg}, rules=False)["pos"] != g["pos"], word exist = G.word_gemination("ያለው", [{"seg": "የ----<ኣል>አ-ው-----", "freq": 10430, "pos": "V"}, {"seg": "የ-----<ኣ/ለ>አ-ው-----", "freq": 1849, "pos": "AUX"}]) assert exist[0]["pos"] == [1] and "relative_exist" in exist[0]["rules"], exist[0] if __name__ == "__main__": for name, fn in list(globals().items()): if name.startswith("test_") and callable(fn): fn() print("ok", name)