gladia-normalization 0.1.1__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. gladia_normalization-0.2.0/.github/pull_request_template.md +76 -0
  2. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/.gitignore +1 -0
  3. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/AGENTS.md +1 -1
  4. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/CONTRIBUTING.md +1 -1
  5. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/PKG-INFO +35 -5
  6. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/README.md +33 -4
  7. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/docs/contributing-guide.md +28 -24
  8. gladia_normalization-0.2.0/normalization/__main__.py +3 -0
  9. gladia_normalization-0.2.0/normalization/cli.py +88 -0
  10. gladia_normalization-0.2.0/normalization/languages/__init__.py +15 -0
  11. gladia_normalization-0.2.0/normalization/languages/dutch/__init__.py +7 -0
  12. gladia_normalization-0.2.0/normalization/languages/dutch/number_normalizer.py +144 -0
  13. gladia_normalization-0.2.0/normalization/languages/dutch/operators.py +160 -0
  14. gladia_normalization-0.2.0/normalization/languages/dutch/replacements.py +28 -0
  15. gladia_normalization-0.2.0/normalization/languages/dutch/sentence_replacements.py +9 -0
  16. gladia_normalization-0.2.0/normalization/languages/french/number_normalizer.py +72 -0
  17. gladia_normalization-0.2.0/normalization/languages/french/operators.py +138 -0
  18. gladia_normalization-0.2.0/normalization/languages/french/replacements.py +28 -0
  19. gladia_normalization-0.2.0/normalization/languages/french/sentence_replacements.py +13 -0
  20. gladia_normalization-0.2.0/normalization/languages/german/__init__.py +7 -0
  21. gladia_normalization-0.2.0/normalization/languages/german/number_normalizer.py +67 -0
  22. gladia_normalization-0.2.0/normalization/languages/german/operators.py +93 -0
  23. gladia_normalization-0.2.0/normalization/languages/german/replacements.py +10 -0
  24. gladia_normalization-0.2.0/normalization/languages/german/sentence_replacements.py +16 -0
  25. gladia_normalization-0.2.0/normalization/languages/italian/__init__.py +7 -0
  26. gladia_normalization-0.2.0/normalization/languages/italian/number_normalizer.py +58 -0
  27. gladia_normalization-0.2.0/normalization/languages/italian/operators.py +109 -0
  28. gladia_normalization-0.2.0/normalization/languages/italian/replacements.py +11 -0
  29. gladia_normalization-0.2.0/normalization/languages/italian/sentence_replacements.py +3 -0
  30. gladia_normalization-0.2.0/normalization/languages/spanish/__init__.py +7 -0
  31. gladia_normalization-0.2.0/normalization/languages/spanish/number_normalizer.py +196 -0
  32. gladia_normalization-0.2.0/normalization/languages/spanish/operators.py +139 -0
  33. gladia_normalization-0.2.0/normalization/languages/spanish/replacements.py +30 -0
  34. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/pyproject.toml +12 -2
  35. gladia_normalization-0.2.0/tests/e2e/files/gladia-3/de.csv +45 -0
  36. gladia_normalization-0.2.0/tests/e2e/files/gladia-3/default.csv +11 -0
  37. gladia_normalization-0.2.0/tests/e2e/files/gladia-3/en.csv +132 -0
  38. gladia_normalization-0.2.0/tests/e2e/files/gladia-3/es.csv +38 -0
  39. gladia_normalization-0.2.0/tests/e2e/files/gladia-3/fr.csv +54 -0
  40. gladia_normalization-0.2.0/tests/e2e/files/gladia-3/it.csv +72 -0
  41. gladia_normalization-0.2.0/tests/e2e/files/gladia-3/nl.csv +35 -0
  42. gladia_normalization-0.2.0/tests/e2e/normalization_test.py +90 -0
  43. gladia_normalization-0.2.0/tests/unit/languages/dutch_number_normalizer_test.py +68 -0
  44. gladia_normalization-0.2.0/tests/unit/languages/dutch_operators_test.py +51 -0
  45. gladia_normalization-0.2.0/tests/unit/steps/text/apply_sentence_level_replacements_test.py +18 -0
  46. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/unit/steps/text/conftest.py +12 -0
  47. gladia_normalization-0.2.0/tests/unit/steps/text/expand_contractions_test.py +21 -0
  48. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/uv.lock +97 -1
  49. gladia_normalization-0.1.1/.github/pull_request_template.md +0 -43
  50. gladia_normalization-0.1.1/normalization/languages/__init__.py +0 -7
  51. gladia_normalization-0.1.1/normalization/languages/french/operators.py +0 -38
  52. gladia_normalization-0.1.1/normalization/languages/french/replacements.py +0 -1
  53. gladia_normalization-0.1.1/tests/e2e/files/gladia-3.csv +0 -126
  54. gladia_normalization-0.1.1/tests/e2e/normalization_test.py +0 -68
  55. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/.commitlintrc.json +0 -0
  56. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/.github/workflows/cd.yml +0 -0
  57. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/.github/workflows/ci.yml +0 -0
  58. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/.pre-commit-config.yaml +0 -0
  59. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/.python-version +0 -0
  60. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/CLAUDE.md +0 -0
  61. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/LICENSE +0 -0
  62. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/docs/steps.md +0 -0
  63. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/__init__.py +0 -0
  64. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/constants/__init__.py +0 -0
  65. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/constants/protectors.py +0 -0
  66. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/languages/base/__init__.py +0 -0
  67. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/languages/base/language_config.py +0 -0
  68. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/languages/base/language_operator.py +0 -0
  69. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/languages/english/__init__.py +0 -0
  70. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/languages/english/number_normalizer.py +0 -0
  71. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/languages/english/operators.py +0 -0
  72. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/languages/english/replacements.py +0 -0
  73. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/languages/english/sentence_replacements.py +0 -0
  74. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/languages/french/__init__.py +0 -0
  75. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/languages/registry.py +0 -0
  76. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/pipeline/__init__.py +0 -0
  77. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/pipeline/base.py +0 -0
  78. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/pipeline/loader.py +0 -0
  79. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/pipeline/replacer.py +0 -0
  80. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/presets/gladia-3.yaml +0 -0
  81. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/__init__.py +0 -0
  82. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/base/__init__.py +0 -0
  83. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/base/protect_step.py +0 -0
  84. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/base/restore_step.py +0 -0
  85. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/base/text_step.py +0 -0
  86. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/base/word_step.py +0 -0
  87. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/registry.py +0 -0
  88. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/__init__.py +0 -0
  89. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/apply_sentence_level_replacements.py +0 -0
  90. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/casefold_text.py +0 -0
  91. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/convert_comparison_operators_to_words.py +0 -0
  92. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/convert_decimal_periods_to_decimal_word.py +0 -0
  93. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/convert_degree_symbols_to_words.py +0 -0
  94. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/convert_digit_word_sequences_to_digits.py +0 -0
  95. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/convert_dots_to_words_in_technical_contexts.py +0 -0
  96. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/convert_oclock_to_numeric_time.py +0 -0
  97. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/convert_roman_numerals_to_digits.py +0 -0
  98. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/convert_word_based_time_patterns.py +0 -0
  99. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/expand_alphanumeric_codes.py +0 -0
  100. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/expand_contractions.py +0 -0
  101. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/expand_written_numbers_to_digits.py +0 -0
  102. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/expand_www_abbreviation.py +0 -0
  103. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/fix_ampm_letter_spacing.py +0 -0
  104. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/fix_dot_adjacent_number_words.py +0 -0
  105. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/fix_one_word_in_numeric_contexts.py +0 -0
  106. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/fix_version_number_v_prefix.py +0 -0
  107. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/format_time_patterns_with_ampm.py +0 -0
  108. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/normalize_numeric_time_formats.py +0 -0
  109. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/normalize_punctuation_between_number_words.py +0 -0
  110. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/placeholders.py +0 -0
  111. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/protect_plus_word_before_digit_words.py +0 -0
  112. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/remove_acronym_periods.py +0 -0
  113. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/remove_diacritics.py +0 -0
  114. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/remove_filler_words.py +0 -0
  115. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/remove_hash_before_numbers.py +0 -0
  116. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/remove_non_numeric_trailing_dots.py +0 -0
  117. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/remove_spaces_between_adjacent_digits.py +0 -0
  118. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/remove_standalone_currency_symbols.py +0 -0
  119. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/remove_symbols.py +0 -0
  120. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/remove_thousand_separators.py +0 -0
  121. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/remove_trailing_apostrophe_space.py +0 -0
  122. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/remove_trailing_dot_word_from_emails.py +0 -0
  123. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/remove_trailing_period.py +0 -0
  124. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/remove_zero_minutes_from_time.py +0 -0
  125. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/text/replace_currency.py +0 -0
  126. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/word/__init__.py +0 -0
  127. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/normalization/steps/word/apply_word_replacements.py +0 -0
  128. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/scripts/generate_step_docs.py +0 -0
  129. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/__init__.py +0 -0
  130. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/e2e/__init__.py +0 -0
  131. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/e2e/default_pipeline_test.py +0 -0
  132. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/e2e/latency_test.py +0 -0
  133. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/unit/languages/__init__.py +0 -0
  134. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/unit/languages/english_registry_test.py +0 -0
  135. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/unit/languages/symbols_to_words_test.py +0 -0
  136. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/unit/languages/word_replacement_test.py +0 -0
  137. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/unit/steps/__init__.py +0 -0
  138. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/unit/steps/text/__init__.py +0 -0
  139. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/unit/steps/text/convert_dots_to_words_in_technical_contexts_test.py +0 -0
  140. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/unit/steps/text/convert_oclock_to_numeric_time_test.py +0 -0
  141. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/unit/steps/text/convert_roman_numerals_to_digits_test.py +0 -0
  142. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/unit/steps/text/convert_word_based_time_patterns_test.py +0 -0
  143. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/unit/steps/text/protect_decimal_separator_test.py +0 -0
  144. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/unit/steps/text/remove_diacritics_test.py +0 -0
  145. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/unit/steps/text/remove_zero_minutes_from_time_test.py +0 -0
  146. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/unit/steps/text/replace_currency_test.py +0 -0
  147. {gladia_normalization-0.1.1 → gladia_normalization-0.2.0}/tests/unit/steps/text/restore_decimal_separator_with_word_test.py +0 -0
@@ -0,0 +1,76 @@
1
+ ## What does this PR do?
2
+
3
+ <!-- One sentence: what changed and why. -->
4
+
5
+ ## Type of change
6
+
7
+ - [ ] New language
8
+ - [ ] Edit existing language (fix a replacement, tweak config, …)
9
+ - [ ] New normalization step
10
+ - [ ] Edit existing step (bug fix, behaviour change)
11
+ - [ ] New preset version
12
+ - [ ] Bug fix (other)
13
+ - [ ] Refactor / docs / CI
14
+
15
+ ---
16
+
17
+ ## Checklist
18
+
19
+ **Only fill in the section(s) that match your change — delete the rest.**
20
+
21
+ ---
22
+
23
+ ### New language
24
+
25
+ - [ ] Created `normalization/languages/{lang}/` with `operators.py`, `replacements.py`, `__init__.py`
26
+ - [ ] Word substitutions are in `replacements.py` (not hardcoded in `operators.py`)
27
+ - [ ] `LanguageConfig` is filled in with the language's data (separators, currency words, digit words, …)
28
+ - [ ] Subclassed `LanguageOperators` — only override methods where the **logic** changes, not just the data
29
+ - [ ] Class is decorated with `@register_language` and imported in `normalization/languages/__init__.py`
30
+ - [ ] Unit tests added in `tests/unit/languages/`
31
+ - [ ] E2e CSV added in `tests/e2e/files/{preset}/{lang}.csv` (e.g. `tests/e2e/files/gladia-3/fr.csv`)
32
+
33
+ ---
34
+
35
+ ### Edit existing language
36
+
37
+ - [ ] New/changed word substitutions go in `replacements.py`, not inline in `operators.py`
38
+ - [ ] If you changed a config field that can be `None`: the step reading it still handles `None` gracefully
39
+ - [ ] Unit tests updated or added
40
+ - [ ] E2e CSV updated if the expected output changed
41
+
42
+ ---
43
+
44
+ ### New step
45
+
46
+ - [ ] Unique `name` class attribute set (this is the key used in YAML presets)
47
+ - [ ] Decorated with `@register_step` and imported in `steps/text/__init__.py` or `steps/word/__init__.py`
48
+ - [ ] No hardcoded language values — read data from `operators.config.*` instead
49
+ - [ ] If placeholder-based: protect + restore are both in `steps/text/placeholders.py` and `pipeline/base.py`'s `validate()` is updated
50
+ - [ ] Unit tests added in `tests/unit/steps/`
51
+ - [ ] Step name added to the relevant preset YAML — or a **new preset file** created if existing presets are affected
52
+ - [ ] If the docstring changed: ran `uv run scripts/generate_step_docs.py`
53
+
54
+ ---
55
+
56
+ ### Edit existing step
57
+
58
+ - [ ] Step `name` is unchanged — if the output changes, create a new step name + new preset instead
59
+ - [ ] No language-specific logic or string literals added inside the step
60
+ - [ ] Unit tests updated or added
61
+ - [ ] If the docstring changed: ran `uv run scripts/generate_step_docs.py`
62
+
63
+ ---
64
+
65
+ ### Preset change
66
+
67
+ - [ ] Existing preset files are **not modified** — new behaviour goes in a new preset file
68
+ - [ ] `pipeline.validate()` passes (runs automatically via `loader.py`)
69
+
70
+ ---
71
+
72
+ ## How was this tested?
73
+
74
+ ```
75
+ uv run pytest tests/
76
+ ```
@@ -7,6 +7,7 @@ wheels/
7
7
  *.egg-info
8
8
  .ruff_cache/
9
9
  .pytest_cache/
10
+ .DS_Store
10
11
 
11
12
 
12
13
  # Virtual environments
@@ -144,7 +144,7 @@ Never modify a published preset YAML. Never let a preset reference a step that h
144
144
  - [ ] Decorate the class with `@register_language`
145
145
  - [ ] Add one import to `languages/__init__.py`
146
146
  - [ ] Add tests in `tests/unit/languages/`
147
- - [ ] Add test rows to `tests/e2e/files/` for the new language
147
+ - [ ] Add a CSV file `tests/e2e/files/{preset}/{language_code}.csv` for each relevant preset (e.g. `tests/e2e/files/gladia-3/fr.csv`)
148
148
 
149
149
  ## Adding a new step — checklist
150
150
 
@@ -18,7 +18,7 @@ A new language requires:
18
18
  2. Put all word-level substitutions in `replacements.py`
19
19
  3. Instantiate a `LanguageConfig` and subclass `LanguageOperators` in `operators.py`
20
20
  4. Decorate with `@register_language` and add one import to `normalization/languages/__init__.py`
21
- 5. Add tests under `tests/unit/languages/` and e2e fixture rows in `tests/e2e/files/`
21
+ 5. Add tests under `tests/unit/languages/` and a per-language CSV in `tests/e2e/files/{preset}/` (e.g. `tests/e2e/files/gladia-3/fr.csv`)
22
22
 
23
23
  See [docs/contributing-guide.md](docs/contributing-guide.md) for the full checklist and design rules.
24
24
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gladia-normalization
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Summary: Normalize speech-to-text output for fair Word Error Rate (WER) comparison
5
5
  Project-URL: Homepage, https://github.com/gladiaio/normalization
6
6
  Project-URL: Repository, https://github.com/gladiaio/normalization
@@ -39,6 +39,7 @@ Classifier: Topic :: Text Processing :: Linguistic
39
39
  Requires-Python: >=3.10
40
40
  Requires-Dist: contractions>=0.1.73
41
41
  Requires-Dist: pyyaml>=6.0.3
42
+ Requires-Dist: text2num>=3.0.0
42
43
  Description-Content-Type: text/markdown
43
44
 
44
45
  <p align="center">
@@ -114,6 +115,31 @@ pipeline.normalize("It's $50 at 3:00PM")
114
115
  # => "it is 50 dollars at 3 pm"
115
116
  ```
116
117
 
118
+ ### CLI
119
+
120
+ ```bash
121
+ # Normalize a single text
122
+ gladia-normalization "A tea cost £2 at 3:30PM" --language en
123
+
124
+ # Normalize a text file
125
+ gladia-normalization --file transcript.txt --language en
126
+
127
+ # Pipe from stdin
128
+ echo "A tea cost £2 at 3:30PM" | gladia-normalization --language fr
129
+
130
+ # Use a custom preset
131
+ gladia-normalization "A tea cost £2 at 3:30PM" --preset path/to/my-preset.yaml --language en
132
+
133
+ # Inspect the pipeline
134
+ gladia-normalization --describe --language en
135
+ ```
136
+
137
+ If you don't want a permanent installation, run it directly with `uvx`:
138
+
139
+ ```bash
140
+ uvx gladia-normalization "A tea cost £2 at 3:30PM" --language en
141
+ ```
142
+
117
143
  ## How it works
118
144
 
119
145
  Every pipeline runs exactly **three stages**, always in this order:
@@ -128,10 +154,14 @@ Pipelines are defined declaratively in **YAML presets**. Each preset lists the s
128
154
 
129
155
  ## Supported languages
130
156
 
131
- | Code | Language |
132
- | ---- | -------------- |
133
- | `en` | English |
134
- | `fr` | French (alpha) |
157
+ | Code | Language |
158
+ | ---- | -------- |
159
+ | `en` | English |
160
+ | `fr` | French |
161
+ | `de` | German |
162
+ | `it` | Italian |
163
+ | `es` | Spanish |
164
+ | `nl` | Dutch |
135
165
 
136
166
  Unsupported language codes fall back to a safe default that applies language-independent normalization only.
137
167
 
@@ -71,6 +71,31 @@ pipeline.normalize("It's $50 at 3:00PM")
71
71
  # => "it is 50 dollars at 3 pm"
72
72
  ```
73
73
 
74
+ ### CLI
75
+
76
+ ```bash
77
+ # Normalize a single text
78
+ gladia-normalization "A tea cost £2 at 3:30PM" --language en
79
+
80
+ # Normalize a text file
81
+ gladia-normalization --file transcript.txt --language en
82
+
83
+ # Pipe from stdin
84
+ echo "A tea cost £2 at 3:30PM" | gladia-normalization --language fr
85
+
86
+ # Use a custom preset
87
+ gladia-normalization "A tea cost £2 at 3:30PM" --preset path/to/my-preset.yaml --language en
88
+
89
+ # Inspect the pipeline
90
+ gladia-normalization --describe --language en
91
+ ```
92
+
93
+ If you don't want a permanent installation, run it directly with `uvx`:
94
+
95
+ ```bash
96
+ uvx gladia-normalization "A tea cost £2 at 3:30PM" --language en
97
+ ```
98
+
74
99
  ## How it works
75
100
 
76
101
  Every pipeline runs exactly **three stages**, always in this order:
@@ -85,10 +110,14 @@ Pipelines are defined declaratively in **YAML presets**. Each preset lists the s
85
110
 
86
111
  ## Supported languages
87
112
 
88
- | Code | Language |
89
- | ---- | -------------- |
90
- | `en` | English |
91
- | `fr` | French (alpha) |
113
+ | Code | Language |
114
+ | ---- | -------- |
115
+ | `en` | English |
116
+ | `fr` | French |
117
+ | `de` | German |
118
+ | `it` | Italian |
119
+ | `es` | Spanish |
120
+ | `nl` | Dutch |
92
121
 
93
122
  Unsupported language codes fall back to a safe default that applies language-independent normalization only.
94
123
 
@@ -26,7 +26,7 @@ This ordering is a hard constraint — some steps depend on earlier steps having
26
26
  - [ ] Decorate the class with `@register_language`
27
27
  - [ ] Add one import to `languages/__init__.py`
28
28
  - [ ] Add tests in `tests/unit/languages/`
29
- - [ ] Add test rows to `tests/e2e/files/` for the new language
29
+ - [ ] Add a CSV file `tests/e2e/files/{preset}/{language_code}.csv` for each relevant preset (e.g. `tests/e2e/files/gladia-3/fr.csv`)
30
30
 
31
31
  ### Language data vs. language behavior
32
32
 
@@ -159,42 +159,46 @@ def test_my_step_with_english(english_operators):
159
159
 
160
160
  ### E2E tests for a preset
161
161
 
162
- E2E tests validate the full pipeline (preset + language) against a CSV fixture. The test runner lives in `tests/e2e/normalization_test.py` and CSV files go in `tests/e2e/files/`.
162
+ E2E tests validate the full pipeline (preset + language) against CSV fixtures. The test runner lives in `tests/e2e/normalization_test.py` and CSV files are organized under `tests/e2e/files/`.
163
163
 
164
- **CSV format** — three columns, no quoting needed unless the value contains a comma:
164
+ **Directory structure** — one folder per preset, one CSV per language:
165
165
 
166
166
  ```
167
- input,expected,language
168
- $1,000,000,1000000 dollars,en
169
- hello world,hello world,fr
167
+ tests/e2e/files/
168
+ gladia-3/
169
+ default.csv
170
+ de.csv
171
+ en.csv
172
+ fr.csv
173
+ it.csv
170
174
  ```
171
175
 
172
- Each row is one test case. The `language` column must match a registered language code (or `default`).
176
+ **CSV format** — two columns (`input,expected`), no quoting needed unless the value contains a comma:
173
177
 
174
- **Registering a new CSV** — add a block to `normalization_test.py` following the existing pattern:
178
+ ```
179
+ input,expected
180
+ "$1,000,000",1000000 dollars
181
+ hello world,hello world
182
+ ```
183
+
184
+ The language is derived from the filename (e.g. `fr.csv` → language code `fr`). Use `default.csv` for the language-agnostic fallback.
185
+
186
+ **Adding test cases for an existing preset** — drop rows into the appropriate `{language_code}.csv` file, or create a new CSV if the language isn't covered yet. Tests are discovered automatically.
187
+
188
+ **Registering a new preset** — add a block to `normalization_test.py` following the existing pattern:
175
189
 
176
190
  ```python
177
- _MY_PRESET_CSV = _FILES_DIR / "my-preset.csv"
178
- _MY_PRESET_TESTS = _load_tests_from_csv(_MY_PRESET_CSV) if _MY_PRESET_CSV.exists() else []
191
+ _MY_PRESET_DIR = _FILES_DIR / "my-preset"
192
+ _MY_PRESET_BY_LANGUAGE = _discover_preset_tests(_MY_PRESET_DIR)
179
193
  _MY_PRESET_PIPELINES: dict[str, NormalizationPipeline] = {}
180
194
 
181
-
182
- @pytest.mark.parametrize(
183
- "test",
184
- _MY_PRESET_TESTS,
185
- ids=_case_ids(_MY_PRESET_TESTS),
186
- )
187
- def test_my_preset(test: NormalizationTest) -> None:
188
- pipeline = _load_pipeline("my-preset", test.language)
189
- result = pipeline.normalize(test.input)
190
- assert result == test.expected, (
191
- f"\n input: {test.input!r}"
192
- f"\n expected: {test.expected!r}"
193
- f"\n got: {result!r}"
195
+ for _language in sorted(_MY_PRESET_BY_LANGUAGE):
196
+ globals()[f"test_my_preset_{_language}"] = _make_test(
197
+ "my-preset", _language, _MY_PRESET_BY_LANGUAGE[_language], _MY_PRESET_PIPELINES
194
198
  )
195
199
  ```
196
200
 
197
- Pipelines are cached per language inside `_MY_PRESET_PIPELINES` to avoid reloading for each parametrized case — follow the `_load_pipeline` helper pattern already in the file.
201
+ Pipelines are cached per language to avoid reloading for each parametrized case.
198
202
 
199
203
  ---
200
204
 
@@ -0,0 +1,3 @@
1
+ from normalization.cli import main
2
+
3
+ main()
@@ -0,0 +1,88 @@
1
+ import argparse
2
+ import json
3
+ import sys
4
+
5
+ from normalization import load_pipeline
6
+ from normalization.languages import get_language_registry
7
+ from normalization.pipeline.loader import _PRESETS_DIR
8
+
9
+
10
+ def _available_languages() -> list[str]:
11
+ import normalization.languages # noqa: F401 — triggers @register_language decorators
12
+
13
+ return sorted(get_language_registry().keys())
14
+
15
+
16
+ def _available_presets() -> list[str]:
17
+ return sorted(p.stem for p in _PRESETS_DIR.glob("*.yaml"))
18
+
19
+
20
+ def main() -> None:
21
+ parser = argparse.ArgumentParser(
22
+ prog="normalize",
23
+ description="Normalize STT transcription text for fair WER comparison.",
24
+ )
25
+ parser.add_argument(
26
+ "text",
27
+ nargs="?",
28
+ help="Text to normalize. Reads from stdin if omitted.",
29
+ )
30
+ parser.add_argument(
31
+ "--language",
32
+ "-l",
33
+ default="en",
34
+ metavar="CODE",
35
+ help="Language code (default: en). Available: %(choices)s.",
36
+ choices=_available_languages(),
37
+ )
38
+ parser.add_argument(
39
+ "--preset",
40
+ "-p",
41
+ default="gladia-3",
42
+ metavar="PRESET",
43
+ help="Built-in preset name or path to a YAML file (default: gladia-3).",
44
+ )
45
+ parser.add_argument(
46
+ "--file",
47
+ "-f",
48
+ metavar="PATH",
49
+ help="Path to a text file to normalize. Mutually exclusive with positional text.",
50
+ )
51
+ parser.add_argument(
52
+ "--describe",
53
+ action="store_true",
54
+ help="Print the pipeline description as JSON and exit.",
55
+ )
56
+
57
+ args = parser.parse_args()
58
+
59
+ if args.text is not None and args.file is not None:
60
+ parser.error("Provide either positional text or --file, not both.")
61
+
62
+ try:
63
+ pipeline = load_pipeline(args.preset, args.language)
64
+ except FileNotFoundError as exc:
65
+ parser.error(str(exc))
66
+
67
+ if args.describe:
68
+ print(json.dumps(pipeline.describe(), indent=2))
69
+ return
70
+
71
+ if args.file is not None:
72
+ try:
73
+ with open(args.file) as fh:
74
+ text = fh.read().strip()
75
+ except OSError as exc:
76
+ parser.error(str(exc))
77
+ elif args.text is not None:
78
+ text = args.text
79
+ elif not sys.stdin.isatty():
80
+ text = sys.stdin.read().strip()
81
+ else:
82
+ parser.error("Provide text as an argument, --file, or pipe it via stdin.")
83
+
84
+ print(pipeline.normalize(text))
85
+
86
+
87
+ if __name__ == "__main__":
88
+ main()
@@ -0,0 +1,15 @@
1
+ from . import dutch, english, french, german, italian, spanish
2
+ from .base import LanguageOperators
3
+ from .registry import get_language_registry, register_language
4
+
5
+ register_language(LanguageOperators)
6
+
7
+ __all__ = [
8
+ "dutch",
9
+ "english",
10
+ "french",
11
+ "german",
12
+ "italian",
13
+ "spanish",
14
+ "get_language_registry",
15
+ ]
@@ -0,0 +1,7 @@
1
+ from .operators import DutchOperators
2
+ from .replacements import DUTCH_REPLACEMENTS
3
+
4
+ __all__ = [
5
+ "DutchOperators",
6
+ "DUTCH_REPLACEMENTS",
7
+ ]
@@ -0,0 +1,144 @@
1
+ """Dutch number normalizer using text2num's alpha2digit.
2
+
3
+ Converts spelled-out numbers to digits (e.g. vijf en twintig → 25) and handles
4
+ mixed digit+word forms (e.g. 3 miljard → drie miljard) before conversion so
5
+ alpha2digit does not misinterpret them. Optionally rewrites currency symbols to
6
+ amount + spoken singular unit, then restores plural trailing words from config.
7
+ """
8
+
9
+ import re
10
+
11
+ from text_to_num import alpha2digit
12
+
13
+ # Digit-to-Dutch-word mapping for normalizing "3 miljard" → "drie miljard".
14
+ _DIGIT_TO_DUTCH: dict[str, str] = {
15
+ "0": "nul",
16
+ "1": "een",
17
+ "2": "twee",
18
+ "3": "drie",
19
+ "4": "vier",
20
+ "5": "vijf",
21
+ "6": "zes",
22
+ "7": "zeven",
23
+ "8": "acht",
24
+ "9": "negen",
25
+ }
26
+
27
+ # Pattern: digit(s) followed by Dutch large-number multipliers.
28
+ _RE_MIXED_NUMBER = re.compile(
29
+ r"\b(\d+)\s+(miljoen|miljoenen|miljard|miljarden|biljoen|biljoenen)\b",
30
+ re.IGNORECASE,
31
+ )
32
+
33
+
34
+ def _normalize_mixed_numbers(text: str) -> str:
35
+ """Convert '3 miljard' → 'drie miljard' so alpha2digit yields 3e9, not '3 1000000000'.
36
+
37
+ alpha2digit may concatenate a lone digit with the following word; converting
38
+ the digit to a word avoids that (e.g. 'drie miljard' → 3000000000).
39
+ """
40
+
41
+ def replace(match: re.Match) -> str:
42
+ number = match.group(1)
43
+ multiplier = match.group(2)
44
+ if len(number) == 1 and number in _DIGIT_TO_DUTCH:
45
+ return f"{_DIGIT_TO_DUTCH[number]} {multiplier}"
46
+ # Multi-digit: keep as-is; alpha2digit will handle or leave unchanged
47
+ return match.group(0)
48
+
49
+ return _RE_MIXED_NUMBER.sub(replace, text)
50
+
51
+
52
+ def _singular_spoken_unit(trailing_word: str) -> str:
53
+ """Map ``currency_symbol_to_word`` value to a spoken singular alpha2digit accepts."""
54
+ t = trailing_word.lower()
55
+ if t == "euros":
56
+ return "euro"
57
+ if t == "dollars":
58
+ return "dollar"
59
+ if t == "ponden":
60
+ return "pond"
61
+ if t == "yens":
62
+ return "yen"
63
+ return trailing_word
64
+
65
+
66
+ def _normalize_currency_symbols(
67
+ text: str,
68
+ currency_symbol_to_word: dict[str, str] | None,
69
+ ) -> str:
70
+ if not currency_symbol_to_word:
71
+ return text
72
+ num = r"\d+(?:[.,]\d+)?"
73
+ for symbol, trailing in currency_symbol_to_word.items():
74
+ singular = _singular_spoken_unit(trailing)
75
+ esc = re.escape(symbol)
76
+ text = re.sub(rf"{esc}\s*({num})", rf"\1 {singular}", text, flags=re.IGNORECASE)
77
+ text = re.sub(rf"({num})\s*{esc}", rf"\1 {singular}", text, flags=re.IGNORECASE)
78
+ return text
79
+
80
+
81
+ def _currency_plural_fix_patterns(
82
+ currency_symbol_to_word: dict[str, str] | None,
83
+ ) -> tuple[tuple[re.Pattern[str], str], ...]:
84
+ """Build (pattern, replacement) pairs so digit + alpha2digit singular → config trailing word."""
85
+ if not currency_symbol_to_word:
86
+ return ()
87
+ amount = r"(\d+(?:[.,]\d+)?)"
88
+ seen: set[str] = set()
89
+ out: list[tuple[re.Pattern[str], str]] = []
90
+ for _symbol, trailing in currency_symbol_to_word.items():
91
+ tl = trailing.lower()
92
+ if tl in seen:
93
+ continue
94
+ seen.add(tl)
95
+ singular = _singular_spoken_unit(trailing)
96
+ if singular.lower() == tl:
97
+ continue
98
+ if tl == "euros":
99
+ pat = re.compile(rf"\b{amount}\s+euro(?:'s)?\b", re.IGNORECASE)
100
+ out.append((pat, rf"\1 {trailing}"))
101
+ else:
102
+ pat = re.compile(
103
+ rf"\b{amount}\s+{re.escape(singular)}\b",
104
+ re.IGNORECASE,
105
+ )
106
+ out.append((pat, rf"\1 {trailing}"))
107
+ return tuple(out)
108
+
109
+
110
+ def _apply_currency_plural_fixes(
111
+ text: str,
112
+ fixers: tuple[tuple[re.Pattern[str], str], ...],
113
+ ) -> str:
114
+ for pattern, repl in fixers:
115
+ text = pattern.sub(repl, text)
116
+ return text
117
+
118
+
119
+ class DutchNumberNormalizer:
120
+ """Convert Dutch spelled-out numbers to digits via text2num.alpha2digit.
121
+
122
+ Applies pre-passes for currency symbols (when configured) and mixed digit+word
123
+ forms (e.g. 3 miljard) before calling alpha2digit, then normalizes currency
124
+ words to the plural forms in ``currency_symbol_to_word``.
125
+ """
126
+
127
+ def __init__(self, currency_symbol_to_word: dict[str, str] | None = None) -> None:
128
+ if alpha2digit is None:
129
+ raise ImportError(
130
+ "Dutch number normalization requires the text2num package. "
131
+ "Install it with: uv add text2num"
132
+ )
133
+ self._alpha2digit = alpha2digit
134
+ self._currency_symbol_to_word = currency_symbol_to_word
135
+ self._currency_plural_fixes = _currency_plural_fix_patterns(
136
+ currency_symbol_to_word,
137
+ )
138
+
139
+ def __call__(self, text: str) -> str:
140
+ text = _normalize_currency_symbols(text, self._currency_symbol_to_word)
141
+ text = _normalize_mixed_numbers(text)
142
+ text = self._alpha2digit(text, "nl")
143
+ text = _apply_currency_plural_fixes(text, self._currency_plural_fixes)
144
+ return text