diff --git a/nemo_text_processing/text_normalization/zh/taggers/money.py b/nemo_text_processing/text_normalization/zh/taggers/money.py index d0c6d2ca5..42fa20db3 100644 --- a/nemo_text_processing/text_normalization/zh/taggers/money.py +++ b/nemo_text_processing/text_normalization/zh/taggers/money.py @@ -16,7 +16,7 @@ import pynini from pynini.lib import pynutil -from nemo_text_processing.text_normalization.zh.graph_utils import GraphFst +from nemo_text_processing.text_normalization.zh.graph_utils import NEMO_DIGIT, GraphFst from nemo_text_processing.text_normalization.zh.utils import get_abs_path suffix = pynini.union( @@ -65,6 +65,15 @@ def __init__(self, cardinal: GraphFst, deterministic: bool = True, lm: bool = Fa cardinal = cardinal.just_cardinals + # Accept conventional comma-separated numbers while keeping the cardinal + # grammar responsible for converting the separator-free digit sequence. + grouped_digits = ( + (NEMO_DIGIT - "0") + + pynini.closure(NEMO_DIGIT, 0, 2) + + pynini.closure(pynutil.delete(",") + NEMO_DIGIT**3, 1) + ) + cardinal = (cardinal | grouped_digits @ cardinal).optimize() + currency = pynini.string_file(get_abs_path("data/money/currency_major.tsv")) currency_mandarin = pynini.string_file(get_abs_path("data/money/currency_mandarin.tsv")) graph_digit = pynini.string_file(get_abs_path("data/number/digit.tsv")) @@ -106,12 +115,10 @@ def __init__(self, cardinal: GraphFst, deterministic: bool = True, lm: bool = Fa # larger money as decimals graph_decimal = ( pynutil.insert('integer_part: \"') - + ( - pynini.closure(cardinal, 1) - + pynutil.delete('.') - + pynutil.insert('点') - + pynini.closure((graph_digit | graph_zero), 1) - ) + + cardinal + + pynutil.insert('\" fractional_part: \"') + + pynutil.delete('.') + + pynini.closure((graph_digit | graph_zero), 1) + pynutil.insert("\"") ) graph_decimal_money = ( diff --git a/tests/nemo_text_processing/zh/data_text_normalization/test_cases_money.txt b/tests/nemo_text_processing/zh/data_text_normalization/test_cases_money.txt index 71dd98d71..6348e0941 100644 --- a/tests/nemo_text_processing/zh/data_text_normalization/test_cases_money.txt +++ b/tests/nemo_text_processing/zh/data_text_normalization/test_cases_money.txt @@ -1,10 +1,13 @@ $5~五美元 ¥5~五人民币 $100~一百美元 +$1,234~一千二百三十四美元 +$1,234,567~一百二十三万四千五百六十七美元 €5~五欧元 £100~一百英镑 ₩100~一百韩元 100美元~一百美元 +1,234美元~一千二百三十四美元 500美元~五百美元 5元~五元 5毛~五毛 @@ -13,10 +16,15 @@ $100~一百美元 5块~五块 6毛~六毛 $1.5万~一点五万美元 +$1234.0~一千二百三十四点零美元 +$1,234.0~一千二百三十四点零美元 +1,234.56美元~一千二百三十四点五六美元 3.5万韩元~三点五万韩元 1.5万美元~一点五万美元 我现在能拿出的现金是100000美元~我现在能拿出的现金是十万美元 一份煎饼卖5块一份~一份煎饼卖五块一份 每100美元能兑换700人民币左右~每一百美元能兑换七百人民币左右 您的银行账户余额为$500~您的银行账户余额为五百美元 -洛杉矶的最低工资是每小时$15~洛杉矶的最低工资是每小时十五美元 \ No newline at end of file +洛杉矶的最低工资是每小时$15~洛杉矶的最低工资是每小时十五美元 +价格是$1,234~价格是一千二百三十四美元 +价格是$1234.0~价格是一千二百三十四点零美元