Skip to content

处理千分位符分隔的数值 #782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion fish_speech/text/chn_text_norm/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def _particular(self):
def normalize(self):
text = self.raw_text

# 处理千分位数值例如 12,234.40
pattern = re.compile(r"[0-9]{1,3}(?:,[0-9]{3})*(?:\.[0-9]+)?%?")
matchers = pattern.findall(text)
if matchers:
for matcher in matchers:
text = text.replace(",", "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这会替换整个文本

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实,我修改下


# 规范化日期
pattern = re.compile(
r"\D+((([089]\d|(19|20)\d{2})年)?(\d{1,2}月(\d{1,2}[日号])?)?)"
Expand Down Expand Up @@ -173,5 +180,5 @@ def normalize(self):
print(Text(raw_text="编号:31520181154418。").normalize())
print(Text(raw_text="纯数:2983.07克或12345.60米。").normalize())
print(Text(raw_text="日期:1999年2月20日或09年3月15号。").normalize())
print(Text(raw_text="金钱:12块5,34.5元,20.1万").normalize())
print(Text(raw_text="金钱:12块5,34.5元,20.1万,3,123.20元").normalize())
print(Text(raw_text="特殊:O2O或B2C。").normalize())