gladia-normalization 0.1.1__tar.gz → 0.3.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.
- gladia_normalization-0.3.0/.github/pull_request_template.md +76 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/.gitignore +1 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/AGENTS.md +1 -1
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/CONTRIBUTING.md +1 -1
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/PKG-INFO +39 -6
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/README.md +37 -5
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/docs/contributing-guide.md +31 -24
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/docs/steps.md +25 -4
- gladia_normalization-0.3.0/normalization/__main__.py +3 -0
- gladia_normalization-0.3.0/normalization/cli.py +88 -0
- gladia_normalization-0.3.0/normalization/languages/__init__.py +28 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/languages/base/language_config.py +10 -0
- gladia_normalization-0.3.0/normalization/languages/dutch/__init__.py +7 -0
- gladia_normalization-0.3.0/normalization/languages/dutch/number_normalizer.py +144 -0
- gladia_normalization-0.3.0/normalization/languages/dutch/operators.py +160 -0
- gladia_normalization-0.3.0/normalization/languages/dutch/replacements.py +28 -0
- gladia_normalization-0.3.0/normalization/languages/dutch/sentence_replacements.py +9 -0
- gladia_normalization-0.3.0/normalization/languages/finnish/__init__.py +7 -0
- gladia_normalization-0.3.0/normalization/languages/finnish/number_normalizer.py +457 -0
- gladia_normalization-0.3.0/normalization/languages/finnish/operators.py +103 -0
- gladia_normalization-0.3.0/normalization/languages/finnish/replacements.py +49 -0
- gladia_normalization-0.3.0/normalization/languages/french/number_normalizer.py +72 -0
- gladia_normalization-0.3.0/normalization/languages/french/operators.py +138 -0
- gladia_normalization-0.3.0/normalization/languages/french/replacements.py +28 -0
- gladia_normalization-0.3.0/normalization/languages/french/sentence_replacements.py +13 -0
- gladia_normalization-0.3.0/normalization/languages/german/__init__.py +7 -0
- gladia_normalization-0.3.0/normalization/languages/german/number_normalizer.py +67 -0
- gladia_normalization-0.3.0/normalization/languages/german/operators.py +93 -0
- gladia_normalization-0.3.0/normalization/languages/german/replacements.py +10 -0
- gladia_normalization-0.3.0/normalization/languages/german/sentence_replacements.py +16 -0
- gladia_normalization-0.3.0/normalization/languages/italian/__init__.py +7 -0
- gladia_normalization-0.3.0/normalization/languages/italian/number_normalizer.py +58 -0
- gladia_normalization-0.3.0/normalization/languages/italian/operators.py +109 -0
- gladia_normalization-0.3.0/normalization/languages/italian/replacements.py +11 -0
- gladia_normalization-0.3.0/normalization/languages/italian/sentence_replacements.py +3 -0
- gladia_normalization-0.3.0/normalization/languages/norwegian/__init__.py +7 -0
- gladia_normalization-0.3.0/normalization/languages/norwegian/number_normalizer.py +428 -0
- gladia_normalization-0.3.0/normalization/languages/norwegian/operators.py +120 -0
- gladia_normalization-0.3.0/normalization/languages/norwegian/replacements.py +14 -0
- gladia_normalization-0.3.0/normalization/languages/spanish/__init__.py +7 -0
- gladia_normalization-0.3.0/normalization/languages/spanish/number_normalizer.py +196 -0
- gladia_normalization-0.3.0/normalization/languages/spanish/operators.py +139 -0
- gladia_normalization-0.3.0/normalization/languages/spanish/replacements.py +30 -0
- gladia_normalization-0.3.0/normalization/languages/swedish/__init__.py +7 -0
- gladia_normalization-0.3.0/normalization/languages/swedish/number_normalizer.py +398 -0
- gladia_normalization-0.3.0/normalization/languages/swedish/operators.py +111 -0
- gladia_normalization-0.3.0/normalization/languages/swedish/replacements.py +14 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/convert_roman_numerals_to_digits.py +21 -6
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/expand_alphanumeric_codes.py +10 -2
- gladia_normalization-0.3.0/normalization/steps/text/remove_standalone_currency_symbols.py +88 -0
- gladia_normalization-0.3.0/normalization/steps/text/remove_symbols.py +38 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/replace_currency.py +11 -5
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/pyproject.toml +12 -2
- gladia_normalization-0.3.0/tests/e2e/files/gladia-3/de.csv +45 -0
- gladia_normalization-0.3.0/tests/e2e/files/gladia-3/default.csv +11 -0
- gladia_normalization-0.3.0/tests/e2e/files/gladia-3/en.csv +132 -0
- gladia_normalization-0.3.0/tests/e2e/files/gladia-3/es.csv +38 -0
- gladia_normalization-0.3.0/tests/e2e/files/gladia-3/fi.csv +17 -0
- gladia_normalization-0.3.0/tests/e2e/files/gladia-3/fr.csv +54 -0
- gladia_normalization-0.3.0/tests/e2e/files/gladia-3/it.csv +72 -0
- gladia_normalization-0.3.0/tests/e2e/files/gladia-3/nl.csv +35 -0
- gladia_normalization-0.3.0/tests/e2e/files/gladia-3/no.csv +20 -0
- gladia_normalization-0.3.0/tests/e2e/files/gladia-3/sv.csv +18 -0
- gladia_normalization-0.3.0/tests/e2e/normalization_test.py +90 -0
- gladia_normalization-0.3.0/tests/unit/languages/dutch_number_normalizer_test.py +68 -0
- gladia_normalization-0.3.0/tests/unit/languages/dutch_operators_test.py +51 -0
- gladia_normalization-0.3.0/tests/unit/languages/finnish_number_normalizer_test.py +58 -0
- gladia_normalization-0.3.0/tests/unit/languages/finnish_operators_test.py +29 -0
- gladia_normalization-0.3.0/tests/unit/languages/norwegian_number_normalizer_test.py +74 -0
- gladia_normalization-0.3.0/tests/unit/languages/norwegian_operators_test.py +29 -0
- gladia_normalization-0.3.0/tests/unit/languages/swedish_number_normalizer_test.py +69 -0
- gladia_normalization-0.3.0/tests/unit/languages/swedish_operators_test.py +28 -0
- gladia_normalization-0.3.0/tests/unit/steps/text/apply_sentence_level_replacements_test.py +18 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/unit/steps/text/conftest.py +12 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/unit/steps/text/convert_roman_numerals_to_digits_test.py +31 -0
- gladia_normalization-0.3.0/tests/unit/steps/text/expand_alphanumeric_codes_test.py +38 -0
- gladia_normalization-0.3.0/tests/unit/steps/text/expand_contractions_test.py +21 -0
- gladia_normalization-0.3.0/tests/unit/steps/text/remove_standalone_currency_symbols_test.py +36 -0
- gladia_normalization-0.3.0/tests/unit/steps/text/remove_symbols_test.py +30 -0
- gladia_normalization-0.3.0/tests/unit/steps/text/replace_currency_kr_test.py +14 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/unit/steps/text/replace_currency_test.py +10 -1
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/uv.lock +97 -1
- gladia_normalization-0.1.1/.github/pull_request_template.md +0 -43
- gladia_normalization-0.1.1/normalization/languages/__init__.py +0 -7
- gladia_normalization-0.1.1/normalization/languages/french/operators.py +0 -38
- gladia_normalization-0.1.1/normalization/languages/french/replacements.py +0 -1
- gladia_normalization-0.1.1/normalization/steps/text/remove_standalone_currency_symbols.py +0 -35
- gladia_normalization-0.1.1/normalization/steps/text/remove_symbols.py +0 -24
- gladia_normalization-0.1.1/tests/e2e/files/gladia-3.csv +0 -126
- gladia_normalization-0.1.1/tests/e2e/normalization_test.py +0 -68
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/.commitlintrc.json +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/.github/workflows/cd.yml +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/.github/workflows/ci.yml +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/.pre-commit-config.yaml +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/.python-version +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/CLAUDE.md +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/LICENSE +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/__init__.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/constants/__init__.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/constants/protectors.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/languages/base/__init__.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/languages/base/language_operator.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/languages/english/__init__.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/languages/english/number_normalizer.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/languages/english/operators.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/languages/english/replacements.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/languages/english/sentence_replacements.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/languages/french/__init__.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/languages/registry.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/pipeline/__init__.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/pipeline/base.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/pipeline/loader.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/pipeline/replacer.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/presets/gladia-3.yaml +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/__init__.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/base/__init__.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/base/protect_step.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/base/restore_step.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/base/text_step.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/base/word_step.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/registry.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/__init__.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/apply_sentence_level_replacements.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/casefold_text.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/convert_comparison_operators_to_words.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/convert_decimal_periods_to_decimal_word.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/convert_degree_symbols_to_words.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/convert_digit_word_sequences_to_digits.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/convert_dots_to_words_in_technical_contexts.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/convert_oclock_to_numeric_time.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/convert_word_based_time_patterns.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/expand_contractions.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/expand_written_numbers_to_digits.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/expand_www_abbreviation.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/fix_ampm_letter_spacing.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/fix_dot_adjacent_number_words.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/fix_one_word_in_numeric_contexts.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/fix_version_number_v_prefix.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/format_time_patterns_with_ampm.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/normalize_numeric_time_formats.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/normalize_punctuation_between_number_words.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/placeholders.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/protect_plus_word_before_digit_words.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/remove_acronym_periods.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/remove_diacritics.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/remove_filler_words.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/remove_hash_before_numbers.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/remove_non_numeric_trailing_dots.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/remove_spaces_between_adjacent_digits.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/remove_thousand_separators.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/remove_trailing_apostrophe_space.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/remove_trailing_dot_word_from_emails.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/remove_trailing_period.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/text/remove_zero_minutes_from_time.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/word/__init__.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/normalization/steps/word/apply_word_replacements.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/scripts/generate_step_docs.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/__init__.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/e2e/__init__.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/e2e/default_pipeline_test.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/e2e/latency_test.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/unit/languages/__init__.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/unit/languages/english_registry_test.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/unit/languages/symbols_to_words_test.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/unit/languages/word_replacement_test.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/unit/steps/__init__.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/unit/steps/text/__init__.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/unit/steps/text/convert_dots_to_words_in_technical_contexts_test.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/unit/steps/text/convert_oclock_to_numeric_time_test.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/unit/steps/text/convert_word_based_time_patterns_test.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/unit/steps/text/protect_decimal_separator_test.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/unit/steps/text/remove_diacritics_test.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.0}/tests/unit/steps/text/remove_zero_minutes_from_time_test.py +0 -0
- {gladia_normalization-0.1.1 → gladia_normalization-0.3.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
|
+
```
|
|
@@ -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
|
|
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
|
|
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.
|
|
3
|
+
Version: 0.3.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,14 +154,21 @@ 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
|
|
157
|
+
| Code | Language |
|
|
158
|
+
| ---- | --------- |
|
|
159
|
+
| `en` | English |
|
|
160
|
+
| `fr` | French |
|
|
161
|
+
| `de` | German |
|
|
162
|
+
| `it` | Italian |
|
|
163
|
+
| `es` | Spanish |
|
|
164
|
+
| `nl` | Dutch |
|
|
165
|
+
| `sv` | Swedish |
|
|
166
|
+
| `fi` | Finnish |
|
|
167
|
+
| `no` | Norwegian |
|
|
135
168
|
|
|
136
169
|
Unsupported language codes fall back to a safe default that applies language-independent normalization only.
|
|
137
170
|
|
|
138
|
-
Adding a new language is self-contained — create a folder, register it with a decorator, done. See [Contributing](#
|
|
171
|
+
Adding a new language is self-contained — create a folder, register it with a decorator, done. See [Contributing](CONTRIBUTING.md#add-support-for-a-new-language).
|
|
139
172
|
|
|
140
173
|
## Custom presets
|
|
141
174
|
|
|
@@ -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,14 +110,21 @@ 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
|
|
113
|
+
| Code | Language |
|
|
114
|
+
| ---- | --------- |
|
|
115
|
+
| `en` | English |
|
|
116
|
+
| `fr` | French |
|
|
117
|
+
| `de` | German |
|
|
118
|
+
| `it` | Italian |
|
|
119
|
+
| `es` | Spanish |
|
|
120
|
+
| `nl` | Dutch |
|
|
121
|
+
| `sv` | Swedish |
|
|
122
|
+
| `fi` | Finnish |
|
|
123
|
+
| `no` | Norwegian |
|
|
92
124
|
|
|
93
125
|
Unsupported language codes fall back to a safe default that applies language-independent normalization only.
|
|
94
126
|
|
|
95
|
-
Adding a new language is self-contained — create a folder, register it with a decorator, done. See [Contributing](#
|
|
127
|
+
Adding a new language is self-contained — create a folder, register it with a decorator, done. See [Contributing](CONTRIBUTING.md#add-support-for-a-new-language).
|
|
96
128
|
|
|
97
129
|
## Custom presets
|
|
98
130
|
|
|
@@ -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
|
|
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,49 @@ 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
|
|
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
|
-
**
|
|
164
|
+
**Directory structure** — one folder per preset, one CSV per language:
|
|
165
165
|
|
|
166
166
|
```
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
tests/e2e/files/
|
|
168
|
+
gladia-3/
|
|
169
|
+
default.csv
|
|
170
|
+
de.csv
|
|
171
|
+
en.csv
|
|
172
|
+
es.csv
|
|
173
|
+
fr.csv
|
|
174
|
+
it.csv
|
|
175
|
+
nl.csv
|
|
176
|
+
sv.csv
|
|
170
177
|
```
|
|
171
178
|
|
|
172
|
-
|
|
179
|
+
**CSV format** — two columns (`input,expected`), no quoting needed unless the value contains a comma:
|
|
173
180
|
|
|
174
|
-
|
|
181
|
+
```
|
|
182
|
+
input,expected
|
|
183
|
+
"$1,000,000",1000000 dollars
|
|
184
|
+
hello world,hello world
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
The language is derived from the filename (e.g. `fr.csv` → language code `fr`). Use `default.csv` for the language-agnostic fallback.
|
|
188
|
+
|
|
189
|
+
**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.
|
|
190
|
+
|
|
191
|
+
**Registering a new preset** — add a block to `normalization_test.py` following the existing pattern:
|
|
175
192
|
|
|
176
193
|
```python
|
|
177
|
-
|
|
178
|
-
|
|
194
|
+
_MY_PRESET_DIR = _FILES_DIR / "my-preset"
|
|
195
|
+
_MY_PRESET_BY_LANGUAGE = _discover_preset_tests(_MY_PRESET_DIR)
|
|
179
196
|
_MY_PRESET_PIPELINES: dict[str, NormalizationPipeline] = {}
|
|
180
197
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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}"
|
|
198
|
+
for _language in sorted(_MY_PRESET_BY_LANGUAGE):
|
|
199
|
+
globals()[f"test_my_preset_{_language}"] = _make_test(
|
|
200
|
+
"my-preset", _language, _MY_PRESET_BY_LANGUAGE[_language], _MY_PRESET_PIPELINES
|
|
194
201
|
)
|
|
195
202
|
```
|
|
196
203
|
|
|
197
|
-
Pipelines are cached per language
|
|
204
|
+
Pipelines are cached per language to avoid reloading for each parametrized case.
|
|
198
205
|
|
|
199
206
|
---
|
|
200
207
|
|
|
@@ -75,6 +75,10 @@ Runs before expand_alphanumeric_codes to prevent 'VIII' -> 'V I I I'.
|
|
|
75
75
|
Only converts ii-ix to avoid false positives with single letters like 'I'.
|
|
76
76
|
Skips 'v' when adjacent to digits (version-like contexts: v2, v 12).
|
|
77
77
|
|
|
78
|
+
When ``operators.config.roman_numerals_uppercase_only`` is True, multi-letter
|
|
79
|
+
numerals match only in ALL CAPS (so Swedish/Norwegian ``vi`` / ``Vi`` are not
|
|
80
|
+
read as 6). Standalone ``V`` still matches as 5 for titles like ``Louis V``.
|
|
81
|
+
|
|
78
82
|
### `convert_word_based_time_patterns`
|
|
79
83
|
|
|
80
84
|
**Base class:** `TextStep`
|
|
@@ -86,14 +90,19 @@ operators.config.pm_word, operators.config.oclock_word, and
|
|
|
86
90
|
operators.get_compound_minutes().
|
|
87
91
|
No-op when required config is None.
|
|
88
92
|
|
|
93
|
+
Regex patterns are compiled once per operators config instance and cached
|
|
94
|
+
on the step to avoid recompilation on every call.
|
|
95
|
+
|
|
89
96
|
### `expand_alphanumeric_codes`
|
|
90
97
|
|
|
91
98
|
**Base class:** `TextStep`
|
|
92
99
|
|
|
93
100
|
Space out uppercase words and alphanumeric codes.
|
|
94
101
|
|
|
95
|
-
'ABC123' -> 'A B C 1 2 3'
|
|
96
|
-
|
|
102
|
+
'ABC123' -> 'A B C 1 2 3'. When ``operators.config.expand_all_caps_letter_by_letter``
|
|
103
|
+
is False, pure letter ALL-CAPS tokens (e.g. SMS) are left intact for Nordic-style
|
|
104
|
+
acronym handling. Skips pure numbers, ordinals (1st, 2nd), and protection markers.
|
|
105
|
+
Must run before casefold_text.
|
|
97
106
|
|
|
98
107
|
### `expand_contractions`
|
|
99
108
|
|
|
@@ -329,13 +338,21 @@ Handles ¤ markers by processing segments separately.
|
|
|
329
338
|
|
|
330
339
|
Remove currency symbols that are not adjacent to numbers.
|
|
331
340
|
|
|
341
|
+
Single-character symbols use the classic between/start/end patterns (not
|
|
342
|
+
between two digits). Multi-character keys (e.g. ``kr``) are matched only as
|
|
343
|
+
whole tokens (``\b...\b``) and are skipped when a digit is nearby with
|
|
344
|
+
only whitespace in between, so ordinary words are not corrupted.
|
|
345
|
+
|
|
332
346
|
### `remove_symbols`
|
|
333
347
|
|
|
334
348
|
**Base class:** `TextStep`
|
|
335
349
|
|
|
336
350
|
Replace markers, symbols, and punctuation with spaces.
|
|
337
351
|
|
|
338
|
-
Preserves letters, digits, and all placeholder characters.
|
|
352
|
+
Preserves letters, digits, and all placeholder characters. When
|
|
353
|
+
``symbols_to_words`` defines a word for ``%``, expands ``%`` only when it
|
|
354
|
+
follows a decimal or integer literal (e.g. ``8,75%``), so other ``%`` uses
|
|
355
|
+
stay unchanged.
|
|
339
356
|
|
|
340
357
|
### `remove_thousand_separators`
|
|
341
358
|
|
|
@@ -376,7 +393,11 @@ No-op when either is None.
|
|
|
376
393
|
|
|
377
394
|
**Base class:** `TextStep`
|
|
378
395
|
|
|
379
|
-
Replace currency symbols with their corresponding words.
|
|
396
|
+
Replace currency symbols with their corresponding words next to amounts.
|
|
397
|
+
|
|
398
|
+
Reads ``operators.config.currency_symbol_to_word``. Multi-character symbols
|
|
399
|
+
(e.g. ``kr``) are matched with word boundaries so amounts already written as
|
|
400
|
+
``… kronor`` are not parsed as ``… kr`` + ``onor``.
|
|
380
401
|
|
|
381
402
|
### `restore_decimal_separator_with_word`
|
|
382
403
|
|
|
@@ -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,28 @@
|
|
|
1
|
+
from . import (
|
|
2
|
+
dutch,
|
|
3
|
+
english,
|
|
4
|
+
finnish,
|
|
5
|
+
french,
|
|
6
|
+
german,
|
|
7
|
+
italian,
|
|
8
|
+
norwegian,
|
|
9
|
+
spanish,
|
|
10
|
+
swedish,
|
|
11
|
+
)
|
|
12
|
+
from .base import LanguageOperators
|
|
13
|
+
from .registry import get_language_registry, register_language
|
|
14
|
+
|
|
15
|
+
register_language(LanguageOperators)
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"dutch",
|
|
19
|
+
"english",
|
|
20
|
+
"finnish",
|
|
21
|
+
"french",
|
|
22
|
+
"german",
|
|
23
|
+
"italian",
|
|
24
|
+
"norwegian",
|
|
25
|
+
"spanish",
|
|
26
|
+
"swedish",
|
|
27
|
+
"get_language_registry",
|
|
28
|
+
]
|
|
@@ -75,6 +75,16 @@ class LanguageConfig:
|
|
|
75
75
|
ordinal_suffixes: list[str] | None = None
|
|
76
76
|
"""Ordinal number suffixes for this language (e.g. ["st", "nd", "rd", "th"] for English).
|
|
77
77
|
Used by steps that need to detect ordinal numbers. None = ordinal detection is skipped."""
|
|
78
|
+
roman_numerals_uppercase_only: bool = False
|
|
79
|
+
"""When True, only treat Roman numerals as digits if they appear in ALL CAPS (e.g. VI, VIII).
|
|
80
|
+
|
|
81
|
+
Avoids collisions with Nordic pronouns spelled ``vi``/``Vi``. Default False preserves
|
|
82
|
+
legacy case-insensitive matching for other languages."""
|
|
83
|
+
expand_all_caps_letter_by_letter: bool = True
|
|
84
|
+
"""When False, pure letter ALL-CAPS tokens (e.g. SMS) are not spaced into letters.
|
|
85
|
+
|
|
86
|
+
Nordic STT hypotheses often keep acronyms as one word; default True preserves
|
|
87
|
+
English-style letter-by-letter expansion for CAPS-only tokens."""
|
|
78
88
|
am_word: str | None = None
|
|
79
89
|
"""Canonical AM time designator (e.g. "am" for English).
|
|
80
90
|
Used by am/pm time formatting steps. None = am/pm steps are skipped."""
|