为中文添加了货币计数

This commit is contained in:
Ella Zhang 2025-09-23 02:48:07 -07:00 committed by GitHub
parent 11aa78bd9b
commit 82b458625d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,6 +10,7 @@ import os
from text import symbols as symbols_v1 from text import symbols as symbols_v1
from text import symbols2 as symbols_v2 from text import symbols2 as symbols_v2
special = [ special = [
# ("%", "zh", "SP"), # ("%", "zh", "SP"),
("", "zh", "SP2"), ("", "zh", "SP2"),
@ -17,7 +18,6 @@ special = [
# ('@', 'zh', "SP4")#不搞鬼畜了,和第二版保持一致吧 # ('@', 'zh', "SP4")#不搞鬼畜了,和第二版保持一致吧
] ]
def clean_text(text, language, version=None): def clean_text(text, language, version=None):
if version is None: if version is None:
version = os.environ.get("version", "v2") version = os.environ.get("version", "v2")
@ -31,6 +31,14 @@ def clean_text(text, language, version=None):
if language not in language_module_map: if language not in language_module_map:
language = "en" language = "en"
text = " " text = " "
if language in ("zh"): #处理货币似乎只能这里截胡,不然货币符号会被吞
from text.zh_normalization.num import (
RE_CNY_PREFIX, RE_CNY_SUFFIX, replace_cny_prefix, replace_cny_suffix,
RE_USD_SYMBOL, RE_USD_SUFFIX, replace_usd_symbol, replace_usd_suffix,)
text = RE_CNY_PREFIX.sub(replace_cny_prefix, text)
text = RE_CNY_SUFFIX.sub(replace_cny_suffix, text)
text = RE_USD_SYMBOL.sub(replace_usd_symbol, text)
text = RE_USD_SUFFIX.sub(replace_usd_suffix, text)
for special_s, special_l, target_symbol in special: for special_s, special_l, target_symbol in special:
if special_s in text and language == special_l: if special_s in text and language == special_l:
return clean_special(text, language, special_s, target_symbol, version) return clean_special(text, language, special_s, target_symbol, version)