Skip to content

Fix Spanish number normalizer dropping the mil multiplier after a hundreds-block - #46

Open
selimfedakar wants to merge 1 commit into
gladiaio:mainfrom
selimfedakar:fix-spanish-hundreds-mil-multiplier
Open

selimfedakar wants to merge 1 commit into
gladiaio:mainfrom
selimfedakar:fix-spanish-hundreds-mil-multiplier

Conversation

@selimfedakar

Copy link
Copy Markdown
Contributor

What

Fix a dropped thousands multiplier in the Spanish number normalizer (normalization/languages/spanish/number_normalizer.py, _parse_number).

A hundreds-block (cien/ciento/doscientos…novecientos) optionally followed by a 0–99 remainder returned its value immediately and never checked whether the next word was mil. So the thousands multiplier was silently dropped whenever a hundreds-block carried a sub-part before mil. (The mil lookahead existed only on the standalone 0–99 path and the bare ciento mil special case.)

Fix

Unify the hundreds-block into a single value, then apply the shared mil multiplier check (mirroring the existing 0–99 + mil logic), with a recursive tail parse so a trailing remainder after mil is added.

Before / after (public API)

input before after
doscientos cincuenta mil euros 250 mil euros 250000 euros
ciento cincuenta mil 150 mil 150000
novecientos noventa y nueve mil 999 mil 999000
doscientos cincuenta mil quinientos 250 mil quinientos 250500

Non-regression: doscientos cincuenta → 250, cien → 100, veintitres → 23 all unchanged.

Reachability / tests

spanish/operators.py expand_written_numbers → SpanishNumberNormalizer (used by presets/gladia-3.yaml); confirmed live via load_pipeline("gladia-3", "es").normalize(...). Adds tests/unit/languages/spanish_number_normalizer_test.py (the Spanish normalizer had no dedicated test file); it fails on main for the mil cases and passes with this change. Full suite stays green.

_parse_number returned a hundreds-block (+ optional 0-99 remainder)
immediately without checking for a following 'mil', so the thousands
multiplier was dropped: 'doscientos cincuenta mil' normalized to
'250 mil' instead of '250000'. Unify the hundreds value and apply the
shared mil check (with a recursive tail parse). Adds a Spanish number
normalizer test file (none existed); it fails on main for the mil cases.

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