from ukrainian_word_stress import Stressifier, StressSymbol from ukrainian_accentor_transformer import Accentor accentors = ["model", "vocab", "none"] def stress_replace_and_shift(stressed: str): stressed = stressed.replace( StressSymbol.CombiningAcuteAccent, "+" ) new_stressed = "" start = 0 last = 0 # shift stress symbol by one "при+віт" -> "пр+ивіт" while True: plus_position = stressed.find("+", start) if plus_position != -1: new_stressed += ( stressed[last : plus_position - 1] + "+" + stressed[plus_position - 1] ) start = plus_position + 1 last = start else: new_stressed += stressed[last:] break return new_stressed stressify = Stressifier(stress_symbol=StressSymbol.CombiningAcuteAccent) accentor_transformer = Accentor() def accentification(sentence: str, mode: str): sentence = sentence.replace("+", "") sentence = sentence.replace( StressSymbol.CombiningAcuteAccent, "" ) if (mode == "vocab"): accented_sentence = stressify(sentence) elif (mode == "model"): accented_sentence = accentor_transformer(sentence) else: accented_sentence = sentence return accented_sentence