diff --git a/greek_accentuation/accentuation.py b/greek_accentuation/accentuation.py index beebf72..d0302c5 100644 --- a/greek_accentuation/accentuation.py +++ b/greek_accentuation/accentuation.py @@ -1,9 +1,10 @@ import enum -from .characters import add_diacritic +from .characters import add_diacritic, base from .characters import Accent, Length, Breathing from .syllabify import onset_nucleus_coda, syllabify, syllable_length from .syllabify import syllable_accent, ultima, penult, antepenult +from .syllabify import debreath, rebreath class Accentuation(enum.Enum): @@ -32,18 +33,14 @@ def __ne__(self, other): return not self.__eq__(other) def __lt__(self, other): - other_value = ( - other.raw_value if isinstance(other, Accentuation) else other - ) + other_value = other.raw_value if isinstance(other, Accentuation) else other return self.raw_value < other_value def __le__(self, other): return self.__lt__(other) or self.__eq__(other) def __gt__(self, other): - other_value = ( - other.raw_value if isinstance(other, Accentuation) else other - ) + other_value = other.raw_value if isinstance(other, Accentuation) else other return self.raw_value > other_value def __ge__(self, other): @@ -60,10 +57,22 @@ def syllable_add_accent(s, a): def add_accentuation(s, accentuation): pos, accent = accentuation.value - final = s[1 - pos:] if pos > 1 else [""] + final = s[1 - pos :] if pos > 1 else [""] return "".join(s[:-pos] + [syllable_add_accent(s[-pos], accent)] + final) +def strip_accentuation(word): + "strip accentuation of a given word conserving breathing" + deword = debreath(word) + no_accent_word = "".join([base(a) for a in word]) + return rebreath(no_accent_word) + + +def strip_word(word): + "strip both accentuation and breathing" + return "".join([base(a) for a in word]) + + def display_accentuation(accentuation): return accentuation.name.lower() @@ -116,9 +125,7 @@ def get_accentuation(w): return Accentuation.PROPAROXYTONE -def possible_accentuations( - s, treat_final_AI_OI_short=True, default_short=False -): +def possible_accentuations(s, treat_final_AI_OI_short=True, default_short=False): ultima_length = syllable_length(s[-1], treat_final_AI_OI_short) penult_length = syllable_length(s[-2], False) if len(s) >= 2 else None if ultima_length == Length.UNKNOWN and default_short: @@ -131,16 +138,17 @@ def possible_accentuations( if not (ultima_length == Length.SHORT): yield Accentuation.PERISPOMENON - if (len(s) >= 2 and not - (penult_length == Length.LONG and ultima_length == Length.SHORT)): + if len(s) >= 2 and not ( + penult_length == Length.LONG and ultima_length == Length.SHORT + ): yield Accentuation.PAROXYTONE - if (len(s) >= 2 and not - (penult_length == Length.SHORT or ultima_length == Length.LONG)): + if len(s) >= 2 and not ( + penult_length == Length.SHORT or ultima_length == Length.LONG + ): yield Accentuation.PROPERISPOMENON - if (len(s) >= 3 and not - (ultima_length == Length.LONG)): + if len(s) >= 3 and not (ultima_length == Length.LONG): yield Accentuation.PROPAROXYTONE @@ -155,8 +163,8 @@ def recessive(w, treat_final_AI_OI_short=True, default_short=False): s, sorted( possible_accentuations(s, treat_final_AI_OI_short, default_short), - reverse=True - )[0] + reverse=True, + )[0], ) @@ -167,9 +175,7 @@ def on_penult(w, default_short=False): pre = "" s = syllabify(w) - accentuations = list( - possible_accentuations(s, default_short=default_short) - ) + accentuations = list(possible_accentuations(s, default_short=default_short)) if Accentuation.PROPERISPOMENON in accentuations: return pre + add_accentuation(s, Accentuation.PROPERISPOMENON) elif Accentuation.PAROXYTONE in accentuations: @@ -187,17 +193,13 @@ def persistent(w, lemma, default_short=False): place, accent = accentuation.value s = syllabify(w) - possible = [ - p.value for p in possible_accentuations(s, default_short=default_short) - ] + possible = [p.value for p in possible_accentuations(s, default_short=default_short)] place2 = len(s) - len(syllabify(lemma)) + place accent_pair = (place2, accent) if accent_pair not in possible: if accent == Accent.ACUTE and (place2, Accent.CIRCUMFLEX) in possible: accent_pair = (place2, Accent.CIRCUMFLEX) - elif ( - accent == Accent.CIRCUMFLEX and (place2, Accent.ACUTE) in possible - ): + elif accent == Accent.CIRCUMFLEX and (place2, Accent.ACUTE) in possible: accent_pair = (place2, Accent.ACUTE) else: for i in range(1, 4):