mirror of
https://github.com/storytold/storyteller-ml.git
synced 2026-10-18 00:33:15 +00:00
refactor
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
class BaseNormalization:
|
||||
|
||||
def normalize(self, raw_input_text: str) -> str:
|
||||
return raw_input_text
|
||||
@@ -1,17 +1,14 @@
|
||||
from tts.text.pipeline_components.normalization.base_normalization import BaseNormalization
|
||||
from tts.text.pipeline_components.normalization.common_cleaners import collapse_whitespace
|
||||
from tts.text.pipeline_components.normalization.common_cleaners import convert_to_ascii
|
||||
from tts.text.pipeline_components.normalization.common_cleaners import lowercase
|
||||
|
||||
class EnglishNormalization(BaseNormalization):
|
||||
def normalize_english(raw_input_text: str) -> str:
|
||||
text = convert_to_ascii(raw_input_text)
|
||||
text = lowercase(text)
|
||||
|
||||
def normalize(self, raw_input_text: str) -> str:
|
||||
text = convert_to_ascii(raw_input_text)
|
||||
text = lowercase(text)
|
||||
# TODO: Expand abbreviations
|
||||
# TODO: Expand numbers
|
||||
|
||||
# TODO: Expand abbreviations
|
||||
# TODO: Expand numbers
|
||||
text = collapse_whitespace(text)
|
||||
|
||||
text = collapse_whitespace(text)
|
||||
|
||||
return text
|
||||
return text
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
from tts.text.pipeline_components.normalization.base_normalization import BaseNormalization
|
||||
from tts.text.pipeline_components.normalization.common_cleaners import collapse_whitespace
|
||||
from tts.text.pipeline_components.normalization.common_cleaners import convert_to_ascii
|
||||
from tts.text.pipeline_components.normalization.common_cleaners import lowercase
|
||||
|
||||
class SpanishNormalization(BaseNormalization):
|
||||
def normalize_spanish(raw_input_text: str) -> str:
|
||||
text = convert_to_ascii(raw_input_text)
|
||||
text = lowercase(text)
|
||||
|
||||
def normalize(self, raw_input_text: str) -> str:
|
||||
return raw_input_text
|
||||
# TODO: Expand abbreviations (Spanish)
|
||||
# TODO: Expand numbers (Spanish)
|
||||
|
||||
text = collapse_whitespace(text)
|
||||
|
||||
return text
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
from tts.text.pipeline_components.normalization.english_normalization import EnglishNormalization
|
||||
from tts.text.pipeline_components.normalization.english_normalization import normalize_english
|
||||
|
||||
class TestEnglishNormalization:
|
||||
|
||||
def test_whitespace_collapse(self):
|
||||
normalizer = EnglishNormalization()
|
||||
output = normalizer.normalize(" \t \n normalized \n \t ")
|
||||
output = normalize_english(" \t \n normalized \n \t ")
|
||||
assert output == " normalized "
|
||||
|
||||
def test_lowercase(self):
|
||||
normalizer = EnglishNormalization()
|
||||
output = normalizer.normalize("This is a test of Normalization.")
|
||||
output = normalize_english("This is a test of Normalization.")
|
||||
assert output == "this is a test of normalization."
|
||||
|
||||
Reference in New Issue
Block a user