feat(ffi): add normalize_sentence_lang for multi-language ITN (#83)#84
Merged
Conversation
The library covered all 7 languages for single-expression ITN (normalize_with_lang) and for sentence-level TN (tn_normalize_sentence_lang), but sentence-level ITN was English-only. Non-English dictation (Parakeet STT post-processing) got no number formatting because callers only have full sentences, not clean expressions. Add the symmetric ITN sentence API across every binding layer: - lib: normalize_sentence_lang / normalize_sentence_with_max_span_lang. Two tagger architectures are dispatched: en/fr/de/es use expression-level taggers scanned with the shared sliding window (sentence_loop + new parse_span_lang), while hi/ja/zh taggers already scan the whole sentence in place, so normalize_with_lang is the sentence entry point for them. Unrecognized codes fall back to English. - ffi: nemo_normalize_sentence_lang + header declaration. - swift: NemoTextProcessing.normalizeSentence(_:language:). - wasm: normalizeSentenceLang + node smoke assertion. Tests: multilang_itn_tests.rs (all 7 langs, multi-expression, fallback, edge cases), FFI unit tests, doctest. Full suite green, fmt clean. Known limitation (pre-existing, not introduced here): the Spanish cardinal tagger over-eagerly joins "y" (e.g. "diez y veinte" -> "30"), which sentence-scanning now surfaces more often. Tracked separately as a tagger-quality follow-up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #83.
Problem
The library covered all 7 languages for single-expression ITN (
normalize_with_lang) and for sentence-level TN (tn_normalize_sentence_lang), but sentence-level ITN was English-only. Non-English dictation cleanup (Parakeet STT post-processing) got no number formatting, because callers only have full sentences — not the clean single expressionsnormalize_with_langexpects.Change
Adds the symmetric ITN sentence API across every binding layer:
normalize_sentence_lang(input, lang)+normalize_sentence_with_max_span_lang(...)nemo_normalize_sentence_lang(input, lang)+ header declNemoTextProcessing.normalizeSentence(_:language:)normalizeSentenceLang(input, lang)Two tagger architectures
The interesting part is that ITN languages split into two families, dispatched in
normalize_sentence_with_max_span_lang:en/fr/de/es— expression-level taggers that expect a clean span. These are scanned with the existing sliding window (sentence_loop) via a newparse_span_lang, which delegates to the per-languagetry_*_taggershelpers (already ordered by priority).hi/ja/zh— scanning taggers that already replace number spans in place across the whole input, sonormalize_with_langis the sentence-level entry point for them andmax_span_tokensdoesn't apply."") fall back to English sentence mode.This is why the TN side's single uniform macro couldn't just be copied — the ITN language module sets are non-uniform (e.g.
jahas no whitelist/money/measure,hiaddsaddress).The headline behavior the issue asked for:
Tests
tests/multilang_itn_tests.rs— all 7 languages, multi-expression sentences, English/unknown fallback, empty/whitespace,max_spanbehavior.nemo_normalize_sentence_langincl. null handling).Full suite green (
cargo test,--features ffi,--doc),cargo fmt --checkclean, release+ffi build exports the symbol.Known limitation (pre-existing, not introduced here)
The Spanish cardinal tagger over-eagerly joins
"y"—normalize_with_lang("diez y veinte", "es")already returns"30"onmain. Sentence-scanning makes this reachable more often (e.g."manzanas y diez peras"drops the"y"). This is a tagger-quality issue initn::es::cardinal, independent of the FFI wiring; worth a separate follow-up rather than expanding this PR's scope. Test assertions avoid"y"-joined Spanish cases.