Skip to content

Fix Swedish number normalizer dropping unit ett after a hundreds-block - #47

Open
selimfedakar wants to merge 1 commit into
gladiaio:mainfrom
selimfedakar:fix-swedish-hundreds-unit-one-grouping
Open

selimfedakar wants to merge 1 commit into
gladiaio:mainfrom
selimfedakar:fix-swedish-hundreds-unit-one-grouping

Conversation

@selimfedakar

Copy link
Copy Markdown
Contributor

What

Fix a dropped thousands multiplier in the Swedish number normalizer (normalization/languages/swedish/number_normalizer.py), the same class as the recently-fixed Spanish mil bug (#46).

When a hundreds-block is followed by the unit one (en/ett) as its remainder before a multiplier, the remainder is dropped: _parse_0_99 returns None for a standalone en/ett, so the hundreds block returns early (just 100/300), the following tusen never attaches, and the number splits apart — "hundra ett tusen" (101000) becomes "100 1000".

The Danish sibling is reference-correct here (it already added an equivalent _parse_0_99_after_og helper producing 101000), confirming this is a Swedish gap, not intended behavior.

Fix

Add _parse_0_99_after_hundred (mirroring Danish): parse 0–99 normally, and if that fails, accept a standalone en/ett as unit 1 — but only in the hundreds-remainder position, where it is grammatically unambiguous. Both hundreds branches call it. A phrase-initial bare ett stays a word (so en krona is untouched).

Before / after (public API)

input before after
hundra ett tusen 100 1000 101000
tre hundra ett tusen fem 300 1005 301005

Non-regression: en krona → en krona, ett tusen → 1000, tjugo tusen fem → 20005, två hundra femtio tusen → 250000.

Reachability / tests

SwedishNumberNormalizer.__call__ ← SwedishOperators.expand_written_numbers ← pipeline. Adds a focused test (test_unit_one_after_hundred_keeps_grouping) that fails on main and passes with this change; full unit suite stays green.

Note: the Norwegian and Finnish normalizers appear to share the identical gap — happy to follow up with those (here or in a combined PR) if you prefer.

_parse_0_99 returns None for a standalone 'en'/'ett', so a hundreds-block
with unit-one remainder returned early and the following 'tusen' never
attached: 'hundra ett tusen' normalized to '100 1000' instead of
'101000'. Add _parse_0_99_after_hundred (mirroring the Danish sibling,
which is reference-correct) to accept 'en'/'ett' as unit 1 only in the
unambiguous hundreds-remainder position. Adds a focused test.

This branch has not been deployed

No deployments
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