feat: Enhance text normalization with support for internet slang expansion, currency formatting, and date handling; update debug WAVs interface and settings

This commit is contained in:
JB
2025-12-15 17:27:08 -08:00
parent 0afaaf561b
commit 015435adb6
10 changed files with 472 additions and 74 deletions
+28 -2
View File
@@ -1,9 +1,13 @@
import importlib
import sys
import os
import pytest
# Ensure real optional dependencies are imported before tests that install stubs
# so that available packages (like ebooklib, bs4) aren't replaced with dummy modules.
for module_name in ("ebooklib", "bs4"):
# so that available packages (like ebooklib, bs4, numpy) aren't replaced with dummy modules.
for module_name in ("ebooklib", "bs4", "numpy"):
if module_name not in sys.modules:
try:
importlib.import_module(module_name)
@@ -11,3 +15,25 @@ for module_name in ("ebooklib", "bs4"):
# On environments without the optional dependency, downstream tests
# will install lightweight stubs as needed.
pass
@pytest.fixture(autouse=True, scope="session")
def _isolate_settings_dir(tmp_path_factory: pytest.TempPathFactory):
settings_dir = tmp_path_factory.mktemp("abogen-settings")
os.environ["ABOGEN_SETTINGS_DIR"] = str(settings_dir)
try:
from abogen.utils import get_user_settings_dir
get_user_settings_dir.cache_clear()
except Exception:
pass
try:
from abogen.normalization_settings import clear_cached_settings
clear_cached_settings()
except Exception:
pass
yield
+34
View File
@@ -215,6 +215,40 @@ def test_decades_can_skip_expansion_when_disabled() -> None:
assert "'90s" in normalized
def test_abbreviated_decades_expand_to_spoken_form() -> None:
normalized = _normalize_text("She loved music from the '80s.")
assert "eighties" in normalized.lower()
def test_currency_under_one_dollar_uses_cents() -> None:
normalized = _normalize_text("It cost $0.99.")
folded = normalized.lower().replace("-", " ")
assert "zero dollars" not in folded
assert "cents" in folded
def test_iso_dates_use_locale_order_and_ordinals(monkeypatch) -> None:
monkeypatch.setenv("LC_TIME", "en_US.UTF-8")
normalized = _normalize_text("The date is 2025/12/15.")
folded = normalized.lower().replace("-", " ")
assert "december" in folded
assert "fifteenth" in folded
def test_times_and_acronyms_do_not_say_dot() -> None:
normalized = _normalize_text("Meet at 5 p.m. near the U.S.A. border.")
folded = normalized.lower()
assert " dot " not in folded
def test_internet_slang_expansion_is_configurable() -> None:
normalized = _normalize_text(
"pls knock before entering.",
normalization_overrides={"normalization_internet_slang": True},
)
assert "please" in normalized.lower()
@pytest.mark.skipif(not SPACY_RESOLVER_AVAILABLE, reason="spaCy model unavailable")
def test_spacy_disambiguates_it_has_from_context() -> None:
normalized = _normalize_text("It's been a long time.")