diff --git a/nemo_text_processing/text_normalization/en/taggers/serial.py b/nemo_text_processing/text_normalization/en/taggers/serial.py index 4a5d6bb9d..57a71765c 100644 --- a/nemo_text_processing/text_normalization/en/taggers/serial.py +++ b/nemo_text_processing/text_normalization/en/taggers/serial.py @@ -28,6 +28,7 @@ convert_space, ) from nemo_text_processing.text_normalization.en.utils import get_abs_path, load_labels +from nemo_text_processing.text_normalization.en.verbalizers.ordinal import OrdinalFst as OrdinalVerbalizer def _leading_zero_graph(cardinal: GraphFst) -> "pynini.FstLike": @@ -183,6 +184,14 @@ def __init__(self, cardinal: GraphFst, ordinal: GraphFst, deterministic: bool = serial_graph |= pynini.compose(graph_with_space, serial_graph_alnum.optimize()).optimize() serial_graph = pynini.compose(pynini.closure(NEMO_NOT_SPACE, 2), serial_graph).optimize() + # ordinal followed by hyphenated words, e.g. "3rd-party" -> "third-party" + ordinal_num = pynini.compose( + pynutil.insert('integer: "') + ordinal.graph + pynutil.insert('"'), + OrdinalVerbalizer(deterministic=deterministic).graph, + ) + ordinal_compound = ordinal_num + pynini.closure(pynini.accep("-") + alphas, 1) + serial_graph |= pynutil.add_weight(ordinal_compound, MIN_NEG_WEIGHT).optimize() + # this is not to verbolize "/" as "slash" in cases like "import/export" serial_graph = pynini.compose( pynini.difference( diff --git a/tests/nemo_text_processing/en/data_text_normalization/test_cases_serial.txt b/tests/nemo_text_processing/en/data_text_normalization/test_cases_serial.txt index f142ceb7e..36354018b 100644 --- a/tests/nemo_text_processing/en/data_text_normalization/test_cases_serial.txt +++ b/tests/nemo_text_processing/en/data_text_normalization/test_cases_serial.txt @@ -30,4 +30,9 @@ a 4-kilogram bag~a four-kilogram bag 123/261788/2021~one hundred twenty three/two six one seven eight eight/two thousand twenty one 2*8~two asterisk eight my pnr is t2000~my pnr is t two thousand -your otp is ab9453~your otp is ab nine four five three \ No newline at end of file +your otp is ab9453~your otp is ab nine four five three +3rd-party~third-party +a 21st-century novel~a twenty first-century novel +19th-century art~nineteenth-century art +the 2nd-largest city~the second-largest city +1st-class-mail~first-class-mail \ No newline at end of file