Skip to content

feat(core): "digits" mode for spoken digit-by-digit sequences - #5

Closed
jqueguiner wants to merge 1 commit into
mainfrom
feat/digits-sequence-mode
Closed

feat(core): "digits" mode for spoken digit-by-digit sequences#5
jqueguiner wants to merge 1 commit into
mainfrom
feat/digits-sequence-mode

Conversation

@jqueguiner

Copy link
Copy Markdown
Owner

The cardinal grammar mis-parses digit-by-digit spellings — "two seven five"14, "seven eight three one eight"27 — but dictated house numbers, zip codes and phone-style runs are commonly spelled this way (found analysing ASR transcripts of spoken postal addresses).

Fix

New Converter::to_digits + "digits" conversion type: each whitespace token of a run must be a single-digit number word (0-9) in the target language (via the existing per-language cardinal converter); the run is concatenated instead of summed. Any non-digit or 10+ token makes it decline, so the sentence walker falls back to its longest cardinal parse — a genuine cardinal is never turned into a digit string.

words2num_sentence("Two seven five", "en", "digits")            -> "275"
words2num_sentence("Seven Eight Three One Eight Ave", "en", ..) -> "78318 Ave"
words2num_sentence("one eight nine zero zero one one", "en", ..)-> "1890011"
words2num_sentence("sieben acht drei", "de", "digits")          -> "783"
words2num_sentence("sixty-one hundred Main St", "en", "digits") -> unchanged
  • Language-agnostic (reuses the reverse tables).
  • Non-breaking (new opt-in to type; passes through the Python binder unchanged).
  • Unit test added; digits added to the CLI help.
  • Limitation: the numeric value type collapses a leading zero ("zero one" → 1).

Cardinal parsing mis-handles digit-by-digit spellings — "two seven five"
-> 14, "seven eight three one eight" -> 27 — yet dictated house numbers,
zip codes and phone-style runs are commonly spelled this way (observed in
ASR transcripts of spoken postal addresses).

Add Converter::to_digits and a "digits" conversion type: each whitespace
token of a run must be a single-digit number word (0-9) in the target
language (via the existing per-language cardinal converter); the run is
concatenated instead of summed. Any non-digit or 10+ token declines, so the
sentence walker falls back to its longest cardinal parse — a genuine
cardinal is never turned into a digit string.

  words2num_sentence("Two seven five", "en", "digits")            -> "275"
  words2num_sentence("one eight nine zero zero one one", ...)     -> "1890011"
  words2num_sentence("sieben acht drei", "de", "digits")          -> "783"
  words2num_sentence("sixty-one hundred Main St", "en", "digits") -> unchanged

Pure-Rust core change (words2num2-core), language-agnostic, non-breaking
(new opt-in type; passes through the thin PyO3 binder unchanged), unit
tested. Limitation: the numeric value type collapses a leading zero.
@jqueguiner
jqueguiner force-pushed the feat/digits-sequence-mode branch from 3aaa5e3 to 661b0a6 Compare July 27, 2026 07:31
@jqueguiner jqueguiner closed this Jul 27, 2026
@jqueguiner jqueguiner reopened this Jul 27, 2026
@jqueguiner

Copy link
Copy Markdown
Owner Author

Superseded by a clean-base branch to clear a stale GitHub merge-base glitch.

@jqueguiner jqueguiner closed this Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant