Spaces:
Sleeping
Sleeping
File size: 1,597 Bytes
5ded30a 24d1f5a 7da5a9a 5ded30a 7da5a9a 5ded30a 7da5a9a 5ded30a 7da5a9a 5ded30a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
from ukrainian_word_stress import StressSymbol, Stressifier
import sys
import os
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
from accentor_lib.ukrainian_accentor_transformer import Accentor
def stress_replace_and_shift(stressed: str):
stressed = stressed.replace(
StressSymbol.CombiningAcuteAccent, "+"
)
new_stressed = ""
start = 0
last = 0
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):
if (mode != "none"):
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
# def accentification(sentence: str):
#
# sentence = sentence.replace("+", "")
# sentence = sentence.replace(
# StressSymbol.CombiningAcuteAccent, ""
# )
#
# accented_sentence = accentor_transformer(sentence)
#
# return accented_sentence
|