GPT-SoVITS/test_zh_normalization_date.py
b84330808 4b10d6d1d1 Read yyyy/m/d dates with one-digit month or day (修复一位数月日的日期被读成分数)
RE_DATE2 only accepted two-digit months and days, so 2024/1/1 fell
through to RE_FRAC and was read as 一分之二千零二十四每一, and 2024-3-8
as 二零二四减三减八. A one-digit day must not be followed by another
digit, so 2024/1/32 is still not a date.

Fixes #1657

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 13:38:36 +09:00

34 lines
1.6 KiB
Python

"""Regressions for reading dates in Chinese text normalization, without loading any model."""
import sys
import unittest
from pathlib import Path
sys.path[:0] = [str(Path(__file__).resolve().parent / "GPT_SoVITS")]
from text.zh_normalization.text_normlization import TextNormalizer # noqa: E402
class DateTests(unittest.TestCase):
def setUp(self):
self.normalizer = TextNormalizer()
def test_single_digit_month_and_day(self):
self.assertEqual(self.normalizer.normalize_sentence("2024/1/1"), "二零二四年一月一日")
self.assertEqual(self.normalizer.normalize_sentence("2024-3-8"), "二零二四年三月八日")
self.assertEqual(self.normalizer.normalize_sentence("2024/1/31"), "二零二四年一月三十一日")
self.assertEqual(self.normalizer.normalize_sentence("2024/10/1"), "二零二四年十月一日")
self.assertEqual(self.normalizer.normalize_sentence("会议在2024/9/27举行"), "会议在二零二四年九月二十七日举行")
def test_two_digit_month_and_day(self):
self.assertEqual(self.normalizer.normalize_sentence("2024/09/27"), "二零二四年九月二十七日")
self.assertEqual(self.normalizer.normalize_sentence("2024-01-01"), "二零二四年一月一日")
def test_not_a_date(self):
self.assertEqual(self.normalizer.normalize_sentence("3/4"), "四分之三")
self.assertNotIn("年", self.normalizer.normalize_sentence("2024/13/1"))
self.assertNotIn("年", self.normalizer.normalize_sentence("2024/1/32"))
if __name__ == "__main__":
unittest.main()