Repository navigation
Recurse into rule 0 for zero-valued non-optional substitutions - #20
Open
selimfedakar wants to merge 1 commit into
Open
selimfedakar wants to merge 1 commit into
selimfedakar wants to merge 1 commit into
Conversation
A bare (recurse-into-current-ruleset), non-optional substitution whose value is 0 was unconditionally skipped. ICU instead recurses into the ruleset's exact rule for 0 and emits its text when such a rule exists, dropping it only when there is no rule 0. The unconditional skip silently lost scale words (Irish "míle", Lithuanian "tūkstančių"). Guard the skip with `0 not in ruleset.numeric_rules` at both the quotient and remainder sites. Optional [...] groups and named-ruleset substitutions are unchanged.
This branch has not been deployed
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.
Recurse into rule 0 for zero-valued non-optional substitutions
Problem
When a substitution evaluates to 0,
unicode-rbnfcan silently drop a scale wordthat ICU speaks. This diverges from ICU's RBNF for languages that define an exact
rule for 0 in the ruleset a bare substitution recurses into:
gafichefiche míleltšimtasšimtas tūkstančiųltšimtas vienasšimtas tūkstančių vienasThe scale words
míle(Irish "thousand") andtūkstančių(Lithuanian "thousand")were being dropped whenever the trailing quotient/remainder was exactly 0.
Root cause
In
RbnfEngine.iter_format_number(unicode_rbnf/engine.py), the quotient (<</←←)and remainder (
>>/→→) handlers skip a substitution whose value is 0 when it is abare substitution — one that recurses into the current ruleset (
part.ruleset_name is None)— and non-optional. The skip was unconditional for that case.
ICU does not skip unconditionally: it recurses into the ruleset's exact rule for 0
and emits that rule's text when such a rule exists; it emits nothing only when there
is no rule for 0. Rulesets like Irish and Lithuanian thousands define an exact rule 0
precisely so the scale word is spoken, so the unconditional skip lost it.
Fix
Narrow the skip condition at both sites so a bare, non-optional, value-0 substitution
is dropped only when the ruleset has no exact rule for 0:
When
0 in ruleset.numeric_rules, the substitution is no longer skipped and theexisting recursion runs, so rule 0 emits its text (matching ICU).
Scope is deliberately narrow:
[...]groups are untouched — an optional integer part is still left outof e.g.
0.5.substitution — no spurious zero-word is introduced.
Verification
tests/test_zero_valued_substitution.pycovering thega/ltscale-wordcases plus an English trailing-zero parity assertion (
20 → "twenty",1000 → "one thousand",100 → "one hundred") that must not gain a zero-word.ga/ltassertions fail while theEnglish parity assertion still passes, confirming the tests exercise this path and
the English behavior is unchanged.
ga/lt/hu/akshows improvements only andzero regressions on the zero-valued-substitution emission path.
This PR claims only the zero-valued-substitution emission path. It does not claim
rounding-mode parity with ICU.