From 74263fab9dbbc71f32fe5225218fe16d764ed688 Mon Sep 17 00:00:00 2001 From: Kaan Eraslan Date: Thu, 23 Jan 2020 01:27:19 +0100 Subject: [PATCH 1/2] new strip function added for word --- greek_accentuation/accentuation.py | 55 +++++++++++++++--------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/greek_accentuation/accentuation.py b/greek_accentuation/accentuation.py index beebf72..78580b1 100644 --- a/greek_accentuation/accentuation.py +++ b/greek_accentuation/accentuation.py @@ -1,6 +1,6 @@ import enum -from .characters import add_diacritic +from .characters import add_diacritic, base, debreath, rebreath from .characters import Accent, Length, Breathing from .syllabify import onset_nucleus_coda, syllabify, syllable_length from .syllabify import syllable_accent, ultima, penult, antepenult @@ -32,18 +32,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,9 +56,19 @@ 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 +122,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 +135,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 +160,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 +172,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 +190,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): From 485196c0c343ec5c44fc034f94959bd2f5b443f7 Mon Sep 17 00:00:00 2001 From: Kaan Eraslan Date: Thu, 23 Jan 2020 01:31:45 +0100 Subject: [PATCH 2/2] added rebreath debreath to module statement --- greek_accentuation/accentuation.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/greek_accentuation/accentuation.py b/greek_accentuation/accentuation.py index 78580b1..d0302c5 100644 --- a/greek_accentuation/accentuation.py +++ b/greek_accentuation/accentuation.py @@ -1,9 +1,10 @@ import enum -from .characters import add_diacritic, base, debreath, rebreath +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): @@ -59,12 +60,14 @@ def add_accentuation(s, accentuation): 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])