Recover spoken "year" number forms in the reverse-table backend - #9
Merged
Conversation
The generic (non-en) backend only matched num2words' single canonical
spelling, so common spoken year readings raised "cannot parse":
- two 2-digit groups: "neunzehn neunundneunzig" (de) = 1999
- explicit hundred: "dix-neuf cent quatre-vingt-dix" (fr) = 1990
- glued hundred: "nittonhundranittiosju" (sv) = 1997
- spaced compound that num2words renders glued:
"mille novecento ottantotto" (it) = 1988
Add, in words2num2-core:
- hundred_word(lang): derive the hundred morpheme
(cent/cento/hundert/honderd/hundra) from num2words(200..=900).
- parse_year(lang, text): recover L*100+R (explicit or glued hundred)
and two-group year readings through the existing reverse-table
primitive, so no per-language grammar is needed.
- additive hundreds in parse_scaled_inner ("novecento" 900 + 88),
covering the vowel elision num2words applies when gluing.
- a de-spaced retry in base_convert for glued canonicals.
Every fall-through is last-resort: a canonical number ("vingt trois" =
23) hits the table first and never reaches them. The rust suite (with
new year-form tests) and the 133 python tests pass.
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.
Problem
The generic reverse-table backend (every locale except
en) matches onlynum2words' single canonical spelling of a value. Speech, however, routinely
uses the year reading, which is never the canonical form — so
words2numraised
cannot parseon:neunzehn neunundneunzignegentien zevenennegentignegentienhonderdzevenennegentignittonhundranittiosjudix-neuf cent quatre-vingt-dixmille novecento ottantottoFor a speech-facing library, years are among the most common spoken numbers.
Fix (all in
words2num2-core, table-driven, no per-language grammar)hundred_word(lang)— derives the language's hundred morpheme(
cent/cento/hundert/honderd/hundra) by renderingnum2words(200..=900)and taking the longest common suffix. Probing the fullrange makes the pre-hundred vowel vary (it
quattr-o/se-i/nov-e), sothe morpheme itself is isolated rather than a unit's trailing vowel.
parse_year(lang, text)— recoversL*100 + Rfrom an explicit hundredtoken (fr), a hundred glued into one token (sv/nl), or two 2-digit groups
(de/nl), resolving every part through the existing reverse-table primitive.
parse_scaled_inner—"novecento"(900) +88,covering the vowel elision num2words applies when gluing
(
novecent-ottantotto), which a naive de-space cannot reproduce.base_convertfor glued canonicals.Every path is last-resort: it runs only after the whole-string table hit and
parse_scaledboth decline, so a canonical number (vingt trois= 23) ismatched first and never reaches the fallback. No canonical round-trip changes.
Tests
hundred_morpheme_is_derived,spoken_year_forms,year_forms_via_public_entry(end-to-end throughwords2num).scaled / connector round-trips (
deux mille dix,soixante-neuf mille huit,dos mil veinticuatro, …) are unchanged — 19/19.