Download code/tests/test_text.py from oProfM/LuaNovaV1: direct link, hf CLI and curl.
- Browser
- Download file 2.28 kB
-
https://huggingface.co/oProfM/LuaNovaV1/resolve/main/code/tests/test_text.py
- Command line
-
hf download hf://oProfM/LuaNovaV1/code/tests/test_text.py
-
curl -L -o test_text.py https://huggingface.co/oProfM/LuaNovaV1/resolve/main/code/tests/test_text.py
2.28 kB
| """Tests for PT-BR text normalization, segmentation, and phonetic tokenization.""" | |
| from __future__ import annotations | |
| import shutil | |
| import unittest | |
| from lua_nova_v1.text import normalize_ptbr_text, phonemize | |
| from lua_nova_v1.text.phonemizer import SYMBOL_TO_ID, chunks, tokenize | |
| from lua_nova_v1.utils.audio import finished, sentences, shorter | |
| class TextPipelineTests(unittest.TestCase): | |
| def test_ptbr_normalizer_formats_common_expressions(self) -> None: | |
| raw = "Dia 22/03 às 14h30 custou R$ 45,90." | |
| norm = normalize_ptbr_text(raw) | |
| self.assertIn("vinte e dois de março", norm) | |
| self.assertIn("quatorze horas e trinta minutos", norm) | |
| self.assertIn("quarenta e cinco reais e noventa centavos", norm) | |
| def test_segmentation_handles_abbreviations_and_clauses(self) -> None: | |
| text = "Dr. Silva chegou cedo, tomou café; depois saiu." | |
| sents = sentences(text) | |
| self.assertEqual(len(sents), 1) | |
| self.assertEqual(finished("Olá"), "Olá.") | |
| self.assertEqual(finished("Tudo bem?"), "Tudo bem?") | |
| parts = shorter("um, dois, três") | |
| self.assertEqual(len(parts), 3) | |
| def test_pure_tokenizer_maps_specials_and_stress(self) -> None: | |
| ph = tokenize([(False, [[("k", 0), ("a", 1), ("z", 0), ("ɐ", 0)]]), (True, "?")]) | |
| self.assertEqual(ph.symbols[0], "<bos>") | |
| self.assertEqual(ph.symbols[-1], "<eos>") | |
| self.assertIn("?", ph.symbols) | |
| self.assertEqual(ph.ids[0], SYMBOL_TO_ID["<bos>"]) | |
| self.assertIn(1, ph.stress) | |
| self.assertEqual(ph.unknown, ()) | |
| def test_chunks_preserve_abbreviations_and_decimals(self) -> None: | |
| out = list(chunks("Dr. Silva pagou 3.14 reais, e saiu!")) | |
| text_pieces = [val for is_p, val in out if not is_p] | |
| self.assertIn("Dr. Silva pagou 3.14 reais", text_pieces) | |
| def test_espeak_phonemizer_smoke(self) -> None: | |
| ph = phonemize("Olá, mundo!") | |
| self.assertGreater(len(ph), 4) | |
| self.assertEqual(ph.symbols[0], "<bos>") | |
| self.assertEqual(ph.symbols[-1], "<eos>") | |
| if __name__ == "__main__": | |
| unittest.main() | |