mirror of
https://github.com/denizsafak/abogen.git
synced 2026-09-20 11:40:57 +02:00
refactor: Language Enum with ISO codes
- Language enum: en-US, en-GB, es, fr, hi, it, ja, pt-BR, zh - Engine-specific mappings (kokoro → single-letter) live in pipeline_factory and synthesize - spacy_utils uses Language enum keys for model mapping - split_pattern uses Language enum properties (is_cjk) - Updated all tests to use ISO codes
This commit is contained in:
+20
-20
@@ -12,49 +12,49 @@ from abogen.domain.split_pattern import get_split_pattern
|
||||
|
||||
class TestEnglish:
|
||||
def test_english_sentence(self):
|
||||
assert get_split_pattern("a", "Sentence") == "\n"
|
||||
assert get_split_pattern("en-US", "Sentence") == "\n"
|
||||
|
||||
def test_english_sentence_comma(self):
|
||||
assert get_split_pattern("a", "Sentence + Comma") == "\n"
|
||||
assert get_split_pattern("en-US", "Sentence + Comma") == "\n"
|
||||
|
||||
def test_english_line(self):
|
||||
assert get_split_pattern("a", "Line") == "\n"
|
||||
assert get_split_pattern("en-US", "Line") == "\n"
|
||||
|
||||
def test_english_disabled(self):
|
||||
assert get_split_pattern("a", "Disabled") == "\n"
|
||||
assert get_split_pattern("en-US", "Disabled") == "\n"
|
||||
|
||||
def test_english_b(self):
|
||||
assert get_split_pattern("b", "Sentence") == "\n"
|
||||
def test_english_gb(self):
|
||||
assert get_split_pattern("en-GB", "Sentence") == "\n"
|
||||
|
||||
|
||||
# --- CJK languages ---
|
||||
|
||||
class TestCJK:
|
||||
def test_chinese_disabled(self):
|
||||
pattern = get_split_pattern("z", "Disabled")
|
||||
pattern = get_split_pattern("zh", "Disabled")
|
||||
assert pattern != "\n"
|
||||
assert r"\n+" in pattern
|
||||
|
||||
def test_chinese_line(self):
|
||||
pattern = get_split_pattern("z", "Line")
|
||||
pattern = get_split_pattern("zh", "Line")
|
||||
assert pattern != "\n"
|
||||
assert r"\n+" in pattern
|
||||
|
||||
def test_chinese_sentence(self):
|
||||
pattern = get_split_pattern("z", "Sentence")
|
||||
pattern = get_split_pattern("zh", "Sentence")
|
||||
assert r"\n+" in pattern
|
||||
|
||||
def test_chinese_sentence_comma(self):
|
||||
pattern = get_split_pattern("z", "Sentence + Comma")
|
||||
pattern = get_split_pattern("zh", "Sentence + Comma")
|
||||
assert r"\n+" in pattern
|
||||
|
||||
def test_japanese_disabled(self):
|
||||
pattern = get_split_pattern("j", "Disabled")
|
||||
pattern = get_split_pattern("ja", "Disabled")
|
||||
assert pattern != "\n"
|
||||
assert r"\n+" in pattern
|
||||
|
||||
def test_japanese_sentence(self):
|
||||
pattern = get_split_pattern("j", "Sentence")
|
||||
pattern = get_split_pattern("ja", "Sentence")
|
||||
assert r"\n+" in pattern
|
||||
|
||||
|
||||
@@ -62,18 +62,18 @@ class TestCJK:
|
||||
|
||||
class TestOtherLanguages:
|
||||
def test_spanish_sentence(self):
|
||||
pattern = get_split_pattern("e", "Sentence")
|
||||
pattern = get_split_pattern("es", "Sentence")
|
||||
assert r"\n+" in pattern
|
||||
|
||||
def test_spanish_line(self):
|
||||
assert get_split_pattern("e", "Line") == "\n"
|
||||
assert get_split_pattern("es", "Line") == "\n"
|
||||
|
||||
def test_spanish_disabled(self):
|
||||
# canonical: \n+ for non-CJK Disabled
|
||||
assert get_split_pattern("e", "Disabled") == r"\n+"
|
||||
assert get_split_pattern("es", "Disabled") == r"\n+"
|
||||
|
||||
def test_french_sentence_comma(self):
|
||||
pattern = get_split_pattern("f", "Sentence + Comma")
|
||||
pattern = get_split_pattern("fr", "Sentence + Comma")
|
||||
assert r"\n+" in pattern
|
||||
|
||||
def test_unknown_lang(self):
|
||||
@@ -85,17 +85,17 @@ class TestOtherLanguages:
|
||||
|
||||
class TestPatternStructure:
|
||||
def test_sentence_has_lookbehind(self):
|
||||
pattern = get_split_pattern("e", "Sentence")
|
||||
pattern = get_split_pattern("es", "Sentence")
|
||||
assert r"(?<=" in pattern
|
||||
|
||||
def test_sentence_comma_has_comma_chars(self):
|
||||
pattern = get_split_pattern("e", "Sentence + Comma")
|
||||
pattern = get_split_pattern("es", "Sentence + Comma")
|
||||
assert "," in pattern
|
||||
|
||||
def test_cjk_spacing_uses_star(self):
|
||||
pattern = get_split_pattern("z", "Sentence")
|
||||
pattern = get_split_pattern("zh", "Sentence")
|
||||
assert r"\s*" in pattern
|
||||
|
||||
def test_non_cjk_spacing_uses_plus(self):
|
||||
pattern = get_split_pattern("e", "Sentence")
|
||||
pattern = get_split_pattern("es", "Sentence")
|
||||
assert r"\s+" in pattern
|
||||
|
||||
Reference in New Issue
Block a user