gladia-normalization 0.3.1__tar.gz → 0.4.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.1 → gladia_normalization-0.4.0}/.github/workflows/ci.yml +11 -0
- gladia_normalization-0.4.0/.github/workflows/docs.yml +59 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/.gitignore +4 -1
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/AGENTS.md +1 -1
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/CONTRIBUTING.md +5 -4
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/PKG-INFO +42 -7
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/README.md +38 -5
- gladia_normalization-0.4.0/docs/assets/favicon.svg +4 -0
- gladia_normalization-0.4.0/docs/assets/fonts/GeistMono-Regular.woff2 +0 -0
- gladia_normalization-0.4.0/docs/assets/logo.svg +4 -0
- gladia_normalization-0.4.0/docs/assets/symbol.svg +3 -0
- gladia_normalization-0.4.0/docs/concepts.md +33 -0
- gladia_normalization-0.4.0/docs/contributing/guide.md +213 -0
- gladia_normalization-0.4.0/docs/contributing/index.md +40 -0
- gladia_normalization-0.4.0/docs/getting-started.md +59 -0
- gladia_normalization-0.4.0/docs/index.md +45 -0
- gladia_normalization-0.4.0/docs/languages.md +32 -0
- gladia_normalization-0.4.0/docs/presets.md +47 -0
- {gladia_normalization-0.3.1/docs → gladia_normalization-0.4.0/docs/reference}/steps.md +10 -0
- gladia_normalization-0.4.0/docs/stylesheets/gladia.css +515 -0
- gladia_normalization-0.4.0/docs/usage/cli.md +40 -0
- gladia_normalization-0.4.0/docs/usage/python.md +56 -0
- gladia_normalization-0.4.0/mkdocs.yml +89 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/constants/protectors.py +3 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/__init__.py +6 -0
- gladia_normalization-0.4.0/normalization/languages/arabic/__init__.py +7 -0
- gladia_normalization-0.4.0/normalization/languages/arabic/number_normalizer.py +390 -0
- gladia_normalization-0.4.0/normalization/languages/arabic/operators.py +121 -0
- gladia_normalization-0.4.0/normalization/languages/arabic/replacements.py +9 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/base/language_config.py +11 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/danish/number_normalizer.py +85 -4
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/danish/operators.py +5 -0
- gladia_normalization-0.4.0/normalization/languages/danish/replacements.py +159 -0
- gladia_normalization-0.4.0/normalization/languages/danish/sentence_replacements.py +28 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/english/number_normalizer.py +118 -3
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/english/replacements.py +12 -0
- gladia_normalization-0.4.0/normalization/languages/english/sentence_replacements.py +8 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/french/replacements.py +9 -0
- gladia_normalization-0.4.0/normalization/languages/french/sentence_replacements.py +25 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/german/replacements.py +5 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/german/sentence_replacements.py +3 -0
- gladia_normalization-0.4.0/normalization/languages/portuguese/__init__.py +7 -0
- gladia_normalization-0.4.0/normalization/languages/portuguese/clitics.py +46 -0
- gladia_normalization-0.4.0/normalization/languages/portuguese/number_normalizer.py +168 -0
- gladia_normalization-0.4.0/normalization/languages/portuguese/operators.py +133 -0
- gladia_normalization-0.4.0/normalization/languages/portuguese/replacements.py +24 -0
- gladia_normalization-0.4.0/normalization/languages/portuguese/sentence_replacements.py +13 -0
- gladia_normalization-0.4.0/normalization/languages/romanian/__init__.py +7 -0
- gladia_normalization-0.4.0/normalization/languages/romanian/number_normalizer.py +490 -0
- gladia_normalization-0.4.0/normalization/languages/romanian/operators.py +106 -0
- gladia_normalization-0.4.0/normalization/languages/romanian/replacements.py +14 -0
- gladia_normalization-0.4.0/normalization/languages/romanian/time_normalizer.py +268 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/spanish/replacements.py +2 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/pipeline/base.py +4 -1
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/presets/gladia-3.yaml +8 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/__init__.py +2 -0
- gladia_normalization-0.4.0/normalization/steps/text/apply_character_replacements.py +22 -0
- gladia_normalization-0.4.0/normalization/steps/text/normalize_punctuation_between_number_words.py +69 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/placeholders.py +27 -12
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/remove_spaces_between_adjacent_digits.py +14 -5
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/replace_currency.py +10 -2
- gladia_normalization-0.4.0/overrides/main.html +1 -0
- gladia_normalization-0.4.0/overrides/partials/logo.html +5 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/pyproject.toml +19 -2
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/scripts/generate_step_docs.py +6 -2
- gladia_normalization-0.4.0/tests/e2e/files/gladia-3/ar.csv +34 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/e2e/files/gladia-3/da.csv +8 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/e2e/files/gladia-3/en.csv +30 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/e2e/files/gladia-3/es.csv +1 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/e2e/files/gladia-3/fr.csv +4 -0
- gladia_normalization-0.4.0/tests/e2e/files/gladia-3/pt.csv +29 -0
- gladia_normalization-0.4.0/tests/e2e/files/gladia-3/ro.csv +98 -0
- gladia_normalization-0.4.0/tests/unit/languages/arabic_number_normalizer_test.py +190 -0
- gladia_normalization-0.4.0/tests/unit/languages/arabic_operators_test.py +140 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/languages/danish_number_normalizer_test.py +41 -0
- gladia_normalization-0.4.0/tests/unit/languages/danish_operators_test.py +67 -0
- gladia_normalization-0.4.0/tests/unit/languages/english_number_normalizer_test.py +232 -0
- gladia_normalization-0.4.0/tests/unit/languages/english_replacements_test.py +28 -0
- gladia_normalization-0.4.0/tests/unit/languages/german_voxpopuli_normalization_test.py +43 -0
- gladia_normalization-0.4.0/tests/unit/languages/portuguese_number_normalizer_test.py +31 -0
- gladia_normalization-0.4.0/tests/unit/languages/portuguese_operators_test.py +78 -0
- gladia_normalization-0.4.0/tests/unit/languages/romanian_number_normalizer_test.py +182 -0
- gladia_normalization-0.4.0/tests/unit/languages/romanian_operators_test.py +79 -0
- gladia_normalization-0.4.0/tests/unit/languages/romanian_time_normalizer_test.py +80 -0
- gladia_normalization-0.4.0/tests/unit/steps/text/apply_character_replacements_test.py +24 -0
- gladia_normalization-0.4.0/tests/unit/steps/text/apply_sentence_level_replacements_test.py +45 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/steps/text/replace_currency_test.py +7 -0
- gladia_normalization-0.4.0/uv.lock +1357 -0
- gladia_normalization-0.3.1/docs/contributing-guide.md +0 -216
- gladia_normalization-0.3.1/normalization/languages/danish/replacements.py +0 -5
- gladia_normalization-0.3.1/normalization/languages/english/sentence_replacements.py +0 -3
- gladia_normalization-0.3.1/normalization/languages/french/sentence_replacements.py +0 -13
- gladia_normalization-0.3.1/normalization/steps/text/normalize_punctuation_between_number_words.py +0 -30
- gladia_normalization-0.3.1/tests/unit/languages/danish_operators_test.py +0 -27
- gladia_normalization-0.3.1/tests/unit/steps/text/apply_sentence_level_replacements_test.py +0 -18
- gladia_normalization-0.3.1/uv.lock +0 -532
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/.commitlintrc.json +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/.github/pull_request_template.md +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/.github/workflows/cd.yml +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/.pre-commit-config.yaml +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/.python-version +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/CLAUDE.md +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/LICENSE +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/__main__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/cli.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/constants/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/base/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/base/language_operator.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/danish/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/dutch/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/dutch/number_normalizer.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/dutch/operators.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/dutch/replacements.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/dutch/sentence_replacements.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/english/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/english/operators.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/finnish/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/finnish/number_normalizer.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/finnish/operators.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/finnish/replacements.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/french/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/french/number_normalizer.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/french/operators.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/german/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/german/number_normalizer.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/german/operators.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/italian/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/italian/number_normalizer.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/italian/operators.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/italian/replacements.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/italian/sentence_replacements.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/norwegian/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/norwegian/number_normalizer.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/norwegian/operators.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/norwegian/replacements.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/registry.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/spanish/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/spanish/number_normalizer.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/spanish/operators.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/swedish/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/swedish/number_normalizer.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/swedish/operators.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/languages/swedish/replacements.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/pipeline/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/pipeline/loader.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/pipeline/replacer.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/base/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/base/protect_step.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/base/restore_step.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/base/text_step.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/base/word_step.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/registry.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/apply_sentence_level_replacements.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/casefold_text.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/convert_comparison_operators_to_words.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/convert_decimal_periods_to_decimal_word.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/convert_degree_symbols_to_words.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/convert_digit_word_sequences_to_digits.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/convert_dots_to_words_in_technical_contexts.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/convert_oclock_to_numeric_time.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/convert_roman_numerals_to_digits.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/convert_word_based_time_patterns.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/expand_alphanumeric_codes.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/expand_contractions.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/expand_written_numbers_to_digits.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/expand_www_abbreviation.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/fix_ampm_letter_spacing.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/fix_dot_adjacent_number_words.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/fix_one_word_in_numeric_contexts.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/fix_version_number_v_prefix.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/format_time_patterns_with_ampm.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/normalize_numeric_time_formats.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/protect_plus_word_before_digit_words.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/remove_acronym_periods.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/remove_diacritics.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/remove_filler_words.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/remove_hash_before_numbers.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/remove_non_numeric_trailing_dots.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/remove_standalone_currency_symbols.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/remove_symbols.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/remove_thousand_separators.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/remove_trailing_apostrophe_space.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/remove_trailing_dot_word_from_emails.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/remove_trailing_period.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/text/remove_zero_minutes_from_time.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/word/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/normalization/steps/word/apply_word_replacements.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/e2e/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/e2e/default_pipeline_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/e2e/files/gladia-3/de.csv +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/e2e/files/gladia-3/default.csv +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/e2e/files/gladia-3/fi.csv +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/e2e/files/gladia-3/it.csv +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/e2e/files/gladia-3/nl.csv +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/e2e/files/gladia-3/no.csv +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/e2e/files/gladia-3/sv.csv +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/e2e/latency_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/e2e/normalization_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/languages/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/languages/dutch_number_normalizer_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/languages/dutch_operators_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/languages/english_registry_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/languages/finnish_number_normalizer_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/languages/finnish_operators_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/languages/norwegian_number_normalizer_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/languages/norwegian_operators_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/languages/swedish_number_normalizer_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/languages/swedish_operators_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/languages/symbols_to_words_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/languages/word_replacement_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/steps/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/steps/text/__init__.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/steps/text/conftest.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/steps/text/convert_dots_to_words_in_technical_contexts_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/steps/text/convert_oclock_to_numeric_time_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/steps/text/convert_roman_numerals_to_digits_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/steps/text/convert_word_based_time_patterns_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/steps/text/expand_alphanumeric_codes_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/steps/text/expand_contractions_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/steps/text/protect_decimal_separator_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/steps/text/remove_diacritics_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/steps/text/remove_standalone_currency_symbols_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/steps/text/remove_symbols_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/steps/text/remove_zero_minutes_from_time_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/steps/text/replace_currency_kr_test.py +0 -0
- {gladia_normalization-0.3.1 → gladia_normalization-0.4.0}/tests/unit/steps/text/restore_decimal_separator_with_word_test.py +0 -0
|
@@ -54,3 +54,14 @@ jobs:
|
|
|
54
54
|
python-version: ${{ matrix.python-version }}
|
|
55
55
|
- run: uv sync --group dev
|
|
56
56
|
- run: uv run pytest
|
|
57
|
+
|
|
58
|
+
docs:
|
|
59
|
+
name: Docs (mkdocs)
|
|
60
|
+
runs-on: ubuntu-latest
|
|
61
|
+
steps:
|
|
62
|
+
- uses: actions/checkout@v6
|
|
63
|
+
- uses: astral-sh/setup-uv@v7
|
|
64
|
+
with:
|
|
65
|
+
python-version: "3.13"
|
|
66
|
+
- run: uv sync --group docs
|
|
67
|
+
- run: uv run mkdocs build --strict
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
name: Docs
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
paths:
|
|
7
|
+
- "docs/**"
|
|
8
|
+
- "overrides/**"
|
|
9
|
+
- "mkdocs.yml"
|
|
10
|
+
- "pyproject.toml"
|
|
11
|
+
- "uv.lock"
|
|
12
|
+
- "scripts/generate_step_docs.py"
|
|
13
|
+
- "normalization/**"
|
|
14
|
+
- ".github/workflows/docs.yml"
|
|
15
|
+
workflow_dispatch:
|
|
16
|
+
|
|
17
|
+
permissions:
|
|
18
|
+
contents: read
|
|
19
|
+
|
|
20
|
+
concurrency:
|
|
21
|
+
group: pages
|
|
22
|
+
cancel-in-progress: false
|
|
23
|
+
|
|
24
|
+
jobs:
|
|
25
|
+
build:
|
|
26
|
+
name: Build MkDocs site
|
|
27
|
+
runs-on: ubuntu-latest
|
|
28
|
+
steps:
|
|
29
|
+
- uses: actions/checkout@v6
|
|
30
|
+
|
|
31
|
+
- uses: astral-sh/setup-uv@v7
|
|
32
|
+
with:
|
|
33
|
+
python-version: "3.13"
|
|
34
|
+
|
|
35
|
+
- name: Install dependencies
|
|
36
|
+
run: uv sync --group docs
|
|
37
|
+
|
|
38
|
+
- name: Build site
|
|
39
|
+
run: uv run mkdocs build --strict
|
|
40
|
+
|
|
41
|
+
- name: Upload Pages artifact
|
|
42
|
+
uses: actions/upload-pages-artifact@v5
|
|
43
|
+
with:
|
|
44
|
+
path: site
|
|
45
|
+
|
|
46
|
+
deploy:
|
|
47
|
+
name: Deploy to GitHub Pages
|
|
48
|
+
needs: build
|
|
49
|
+
runs-on: ubuntu-latest
|
|
50
|
+
permissions:
|
|
51
|
+
pages: write
|
|
52
|
+
id-token: write
|
|
53
|
+
environment:
|
|
54
|
+
name: github-pages
|
|
55
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
56
|
+
steps:
|
|
57
|
+
- name: Deploy
|
|
58
|
+
id: deployment
|
|
59
|
+
uses: actions/deploy-pages@v5
|
|
@@ -157,4 +157,4 @@ Never modify a published preset YAML. Never let a preset reference a step that h
|
|
|
157
157
|
- [ ] Add unit tests in `tests/unit/steps/`
|
|
158
158
|
- [ ] If it involves placeholder protection, add both protect and restore to `steps/text/placeholders.py` and update `pipeline/base.py`'s `validate()` accordingly; use `ProtectStep`/`RestoreStep` base classes where the contract fits, otherwise use `TextStep` directly and document why in the docstring
|
|
159
159
|
- [ ] Add the step name to relevant preset YAMLs if needed (new preset version if existing presets are affected)
|
|
160
|
-
- [ ] If you added or changed the class docstring, run `python scripts/generate_step_docs.py` to regenerate `docs/steps.md`
|
|
160
|
+
- [ ] If you added or changed the class docstring, run `python scripts/generate_step_docs.py` to regenerate `docs/reference/steps.md`
|
|
@@ -20,7 +20,7 @@ A new language requires:
|
|
|
20
20
|
4. Decorate with `@register_language` and add one import to `normalization/languages/__init__.py`
|
|
21
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
|
-
See [docs/contributing
|
|
23
|
+
See [docs/contributing/guide.md](docs/contributing/guide.md) for the full checklist and design rules.
|
|
24
24
|
|
|
25
25
|
### Add a new normalization step
|
|
26
26
|
|
|
@@ -33,9 +33,9 @@ A new step requires:
|
|
|
33
33
|
3. Add an import to `steps/text/__init__.py` or `steps/word/__init__.py`
|
|
34
34
|
4. Add unit tests under `tests/unit/steps/`
|
|
35
35
|
5. Add the step name to the relevant preset YAML, or create a new preset version
|
|
36
|
-
6. If you added or changed the class docstring, regenerate `docs/steps.md`: `uv run scripts/generate_step_docs.py`
|
|
36
|
+
6. If you added or changed the class docstring, regenerate `docs/reference/steps.md`: `uv run scripts/generate_step_docs.py`
|
|
37
37
|
|
|
38
|
-
See [docs/contributing
|
|
38
|
+
See [docs/contributing/guide.md](docs/contributing/guide.md) for base class selection and test conventions.
|
|
39
39
|
|
|
40
40
|
### Report a bug
|
|
41
41
|
|
|
@@ -52,7 +52,7 @@ Open a GitHub issue with the `question` label. We're happy to help.
|
|
|
52
52
|
```bash
|
|
53
53
|
git clone https://github.com/gladiaio/normalization.git
|
|
54
54
|
cd normalization
|
|
55
|
-
uv sync
|
|
55
|
+
uv sync --all-groups
|
|
56
56
|
uv run pre-commit install --install-hooks # install hooks once
|
|
57
57
|
```
|
|
58
58
|
|
|
@@ -63,6 +63,7 @@ uv run pytest # run tests
|
|
|
63
63
|
uv run ruff check . # lint
|
|
64
64
|
uv run ruff format . # format
|
|
65
65
|
uv run ty check # type-check
|
|
66
|
+
uv run mkdocs serve # preview docs at http://127.0.0.1:8000
|
|
66
67
|
```
|
|
67
68
|
|
|
68
69
|
---
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: gladia-normalization
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.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
|
+
Project-URL: Documentation, https://gladiaio.github.io/normalization/
|
|
6
7
|
Project-URL: Repository, https://github.com/gladiaio/normalization
|
|
7
8
|
Project-URL: Bug Tracker, https://github.com/gladiaio/normalization/issues
|
|
8
9
|
Author-email: Gladia <support@gladia.io>
|
|
@@ -40,6 +41,7 @@ Requires-Python: >=3.10
|
|
|
40
41
|
Requires-Dist: contractions>=0.1.73
|
|
41
42
|
Requires-Dist: pyyaml>=6.0.3
|
|
42
43
|
Requires-Dist: text2num>=3.0.0
|
|
44
|
+
Requires-Dist: words2num2>=0.5.0
|
|
43
45
|
Description-Content-Type: text/markdown
|
|
44
46
|
|
|
45
47
|
<p align="center">
|
|
@@ -47,7 +49,7 @@ Description-Content-Type: text/markdown
|
|
|
47
49
|
<p align="center">
|
|
48
50
|
A lightweight library for normalizing speech transcripts before computing WER.
|
|
49
51
|
<br />
|
|
50
|
-
<a href="#quick-start">Quick Start</a> · <a href="
|
|
52
|
+
<a href="#quick-start">Quick Start</a> · <a href="https://gladiaio.github.io/normalization/">Documentation</a> · <a href="CONTRIBUTING.md">Contributing</a>
|
|
51
53
|
</p>
|
|
52
54
|
</p>
|
|
53
55
|
|
|
@@ -73,6 +75,13 @@ These aren't transcription errors — they're formatting differences. Without no
|
|
|
73
75
|
|
|
74
76
|
`gladia-normalization` solves this by reducing both the ground truth and the STT output to a shared canonical form _before_ WER is computed, so that only genuine recognition errors affect the score.
|
|
75
77
|
|
|
78
|
+
## Used in Gladia's benchmarks
|
|
79
|
+
|
|
80
|
+
This library is the normalization step behind the WER figures Gladia publishes. Every reference and every provider's output goes through the `gladia-3` preset before WER is computed, so engines are compared on recognition errors, not formatting.
|
|
81
|
+
|
|
82
|
+
- [Speech-to-text benchmarks](https://www.gladia.io/competitors/benchmarks): WER per dataset and provider.
|
|
83
|
+
- [Speech-to-text API comparison](https://www.gladia.io/speech-to-text-api-comparison): blind test and ELO leaderboard.
|
|
84
|
+
|
|
76
85
|
## What it does
|
|
77
86
|
|
|
78
87
|
The library runs your text through a configurable pipeline of normalization steps — expanding contractions, converting symbols to words, removing fillers, casefolding, and more — to produce a clean, canonical output.
|
|
@@ -140,6 +149,30 @@ If you don't want a permanent installation, run it directly with `uvx`:
|
|
|
140
149
|
uvx gladia-normalization "A tea cost £2 at 3:30PM" --language en
|
|
141
150
|
```
|
|
142
151
|
|
|
152
|
+
### Compute WER
|
|
153
|
+
|
|
154
|
+
Normalize both the reference and the hypothesis with the same pipeline, then score them. This example uses [jiwer](https://github.com/jitsi/jiwer):
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
pip install gladia-normalization jiwer
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
import jiwer
|
|
162
|
+
from normalization import load_pipeline
|
|
163
|
+
|
|
164
|
+
pipeline = load_pipeline("gladia-3", language="en")
|
|
165
|
+
|
|
166
|
+
reference = "It's $50 at 3:00PM, Mr. Smith."
|
|
167
|
+
hypothesis = "it is fifty dollars at 3 pm mister smith"
|
|
168
|
+
|
|
169
|
+
jiwer.wer(reference, hypothesis)
|
|
170
|
+
# => 1.33 (formatting differences counted as errors)
|
|
171
|
+
|
|
172
|
+
jiwer.wer(pipeline.normalize(reference), pipeline.normalize(hypothesis))
|
|
173
|
+
# => 0.0
|
|
174
|
+
```
|
|
175
|
+
|
|
143
176
|
## How it works
|
|
144
177
|
|
|
145
178
|
Every pipeline runs exactly **three stages**, always in this order:
|
|
@@ -150,12 +183,13 @@ Every pipeline runs exactly **three stages**, always in this order:
|
|
|
150
183
|
|
|
151
184
|
This ordering is a hard constraint. Some steps depend on earlier steps having run (e.g. a placeholder protecting a decimal point in Stage 1 must be restored in Stage 3, so that `remove_symbols` doesn't destroy it in between).
|
|
152
185
|
|
|
153
|
-
Pipelines are defined declaratively in **YAML presets**. Each preset lists the steps that run in each stage and the order they run in. See the full [step reference](
|
|
186
|
+
Pipelines are defined declaratively in **YAML presets**. Each preset lists the steps that run in each stage and the order they run in. See the full [step reference](https://gladiaio.github.io/normalization/reference/steps/) for every available step.
|
|
154
187
|
|
|
155
188
|
## Supported languages
|
|
156
189
|
|
|
157
190
|
| Code | Language |
|
|
158
191
|
| ---- | -------- |
|
|
192
|
+
| `ar` | Arabic |
|
|
159
193
|
| `da` | Danish |
|
|
160
194
|
| `de` | German |
|
|
161
195
|
| `en` | English |
|
|
@@ -164,6 +198,9 @@ Pipelines are defined declaratively in **YAML presets**. Each preset lists the s
|
|
|
164
198
|
| `fr` | French |
|
|
165
199
|
| `it` | Italian |
|
|
166
200
|
| `nl` | Dutch |
|
|
201
|
+
| `no` | Norwegian |
|
|
202
|
+
| `pt` | Portuguese |
|
|
203
|
+
| `ro` | Romanian |
|
|
167
204
|
| `sv` | Swedish |
|
|
168
205
|
|
|
169
206
|
Unsupported language codes fall back to a safe default that applies language-independent normalization only.
|
|
@@ -184,7 +221,6 @@ stages:
|
|
|
184
221
|
- casefold_text
|
|
185
222
|
- remove_symbols
|
|
186
223
|
- remove_diacritics
|
|
187
|
-
- normalize_whitespace
|
|
188
224
|
|
|
189
225
|
word:
|
|
190
226
|
- apply_word_replacements
|
|
@@ -192,7 +228,6 @@ stages:
|
|
|
192
228
|
text_post:
|
|
193
229
|
- restore_email_at_symbol_with_word
|
|
194
230
|
- restore_email_dot_symbol_with_word
|
|
195
|
-
- normalize_whitespace
|
|
196
231
|
```
|
|
197
232
|
|
|
198
233
|
_Load from your custom configuration:_
|
|
@@ -234,7 +269,7 @@ uv run ty check # type-check
|
|
|
234
269
|
|
|
235
270
|
## About
|
|
236
271
|
|
|
237
|
-
`gladia-normalization` grew out of internal tooling at [Gladia](https://gladia.io), where we are building an audio intelligence platform powered by speech recognition. When benchmarking ASR systems, we kept hitting the same problem: computing WER from raw transcript penalizes formatting differences that have nothing to do with the quality itself. We built this library to solve it for ourselves, then open-sourced it so the broader speech community doesn't have to solve it again.
|
|
272
|
+
`gladia-normalization` grew out of internal tooling at [Gladia](https://www.gladia.io), where we are building an audio intelligence platform powered by speech recognition. When benchmarking ASR systems, we kept hitting the same problem: computing WER from raw transcript penalizes formatting differences that have nothing to do with the quality itself. We built this library to solve it for ourselves, then open-sourced it so the broader speech community doesn't have to solve it again.
|
|
238
273
|
|
|
239
274
|
Sharing it felt like the right next step: the problem is universal, and community contributions are the best way to make reliable normalization available for every language, not just the ones we support today.
|
|
240
275
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<p align="center">
|
|
4
4
|
A lightweight library for normalizing speech transcripts before computing WER.
|
|
5
5
|
<br />
|
|
6
|
-
<a href="#quick-start">Quick Start</a> · <a href="
|
|
6
|
+
<a href="#quick-start">Quick Start</a> · <a href="https://gladiaio.github.io/normalization/">Documentation</a> · <a href="CONTRIBUTING.md">Contributing</a>
|
|
7
7
|
</p>
|
|
8
8
|
</p>
|
|
9
9
|
|
|
@@ -29,6 +29,13 @@ These aren't transcription errors — they're formatting differences. Without no
|
|
|
29
29
|
|
|
30
30
|
`gladia-normalization` solves this by reducing both the ground truth and the STT output to a shared canonical form _before_ WER is computed, so that only genuine recognition errors affect the score.
|
|
31
31
|
|
|
32
|
+
## Used in Gladia's benchmarks
|
|
33
|
+
|
|
34
|
+
This library is the normalization step behind the WER figures Gladia publishes. Every reference and every provider's output goes through the `gladia-3` preset before WER is computed, so engines are compared on recognition errors, not formatting.
|
|
35
|
+
|
|
36
|
+
- [Speech-to-text benchmarks](https://www.gladia.io/competitors/benchmarks): WER per dataset and provider.
|
|
37
|
+
- [Speech-to-text API comparison](https://www.gladia.io/speech-to-text-api-comparison): blind test and ELO leaderboard.
|
|
38
|
+
|
|
32
39
|
## What it does
|
|
33
40
|
|
|
34
41
|
The library runs your text through a configurable pipeline of normalization steps — expanding contractions, converting symbols to words, removing fillers, casefolding, and more — to produce a clean, canonical output.
|
|
@@ -96,6 +103,30 @@ If you don't want a permanent installation, run it directly with `uvx`:
|
|
|
96
103
|
uvx gladia-normalization "A tea cost £2 at 3:30PM" --language en
|
|
97
104
|
```
|
|
98
105
|
|
|
106
|
+
### Compute WER
|
|
107
|
+
|
|
108
|
+
Normalize both the reference and the hypothesis with the same pipeline, then score them. This example uses [jiwer](https://github.com/jitsi/jiwer):
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
pip install gladia-normalization jiwer
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
import jiwer
|
|
116
|
+
from normalization import load_pipeline
|
|
117
|
+
|
|
118
|
+
pipeline = load_pipeline("gladia-3", language="en")
|
|
119
|
+
|
|
120
|
+
reference = "It's $50 at 3:00PM, Mr. Smith."
|
|
121
|
+
hypothesis = "it is fifty dollars at 3 pm mister smith"
|
|
122
|
+
|
|
123
|
+
jiwer.wer(reference, hypothesis)
|
|
124
|
+
# => 1.33 (formatting differences counted as errors)
|
|
125
|
+
|
|
126
|
+
jiwer.wer(pipeline.normalize(reference), pipeline.normalize(hypothesis))
|
|
127
|
+
# => 0.0
|
|
128
|
+
```
|
|
129
|
+
|
|
99
130
|
## How it works
|
|
100
131
|
|
|
101
132
|
Every pipeline runs exactly **three stages**, always in this order:
|
|
@@ -106,12 +137,13 @@ Every pipeline runs exactly **three stages**, always in this order:
|
|
|
106
137
|
|
|
107
138
|
This ordering is a hard constraint. Some steps depend on earlier steps having run (e.g. a placeholder protecting a decimal point in Stage 1 must be restored in Stage 3, so that `remove_symbols` doesn't destroy it in between).
|
|
108
139
|
|
|
109
|
-
Pipelines are defined declaratively in **YAML presets**. Each preset lists the steps that run in each stage and the order they run in. See the full [step reference](
|
|
140
|
+
Pipelines are defined declaratively in **YAML presets**. Each preset lists the steps that run in each stage and the order they run in. See the full [step reference](https://gladiaio.github.io/normalization/reference/steps/) for every available step.
|
|
110
141
|
|
|
111
142
|
## Supported languages
|
|
112
143
|
|
|
113
144
|
| Code | Language |
|
|
114
145
|
| ---- | -------- |
|
|
146
|
+
| `ar` | Arabic |
|
|
115
147
|
| `da` | Danish |
|
|
116
148
|
| `de` | German |
|
|
117
149
|
| `en` | English |
|
|
@@ -120,6 +152,9 @@ Pipelines are defined declaratively in **YAML presets**. Each preset lists the s
|
|
|
120
152
|
| `fr` | French |
|
|
121
153
|
| `it` | Italian |
|
|
122
154
|
| `nl` | Dutch |
|
|
155
|
+
| `no` | Norwegian |
|
|
156
|
+
| `pt` | Portuguese |
|
|
157
|
+
| `ro` | Romanian |
|
|
123
158
|
| `sv` | Swedish |
|
|
124
159
|
|
|
125
160
|
Unsupported language codes fall back to a safe default that applies language-independent normalization only.
|
|
@@ -140,7 +175,6 @@ stages:
|
|
|
140
175
|
- casefold_text
|
|
141
176
|
- remove_symbols
|
|
142
177
|
- remove_diacritics
|
|
143
|
-
- normalize_whitespace
|
|
144
178
|
|
|
145
179
|
word:
|
|
146
180
|
- apply_word_replacements
|
|
@@ -148,7 +182,6 @@ stages:
|
|
|
148
182
|
text_post:
|
|
149
183
|
- restore_email_at_symbol_with_word
|
|
150
184
|
- restore_email_dot_symbol_with_word
|
|
151
|
-
- normalize_whitespace
|
|
152
185
|
```
|
|
153
186
|
|
|
154
187
|
_Load from your custom configuration:_
|
|
@@ -190,7 +223,7 @@ uv run ty check # type-check
|
|
|
190
223
|
|
|
191
224
|
## About
|
|
192
225
|
|
|
193
|
-
`gladia-normalization` grew out of internal tooling at [Gladia](https://gladia.io), where we are building an audio intelligence platform powered by speech recognition. When benchmarking ASR systems, we kept hitting the same problem: computing WER from raw transcript penalizes formatting differences that have nothing to do with the quality itself. We built this library to solve it for ourselves, then open-sourced it so the broader speech community doesn't have to solve it again.
|
|
226
|
+
`gladia-normalization` grew out of internal tooling at [Gladia](https://www.gladia.io), where we are building an audio intelligence platform powered by speech recognition. When benchmarking ASR systems, we kept hitting the same problem: computing WER from raw transcript penalizes formatting differences that have nothing to do with the quality itself. We built this library to solve it for ourselves, then open-sourced it so the broader speech community doesn't have to solve it again.
|
|
194
227
|
|
|
195
228
|
Sharing it felt like the right next step: the problem is universal, and community contributions are the best way to make reliable normalization available for every language, not just the ones we support today.
|
|
196
229
|
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1080 1080">
|
|
2
|
+
<rect width="1080" height="1080" rx="180" fill="#0C0C0C"/>
|
|
3
|
+
<path fill="#fff" transform="translate(140,140) scale(0.74)" d="M557.83,699.88c68.85,0,134.89,27.36,183.59,76.07l188.67,219.28h-109.92c-28.48,0-55.6-12.27-74.42-33.69l-156.27-177.97v296.43h-104.71v-290.03l-150.63,171.53c-18.78,21.38-45.9,33.67-74.42,33.67h-110l188.8-219.28c48.71-48.7,114.75-76.07,183.59-76.07h35.71v.05ZM304.08,338.61c48.7,48.7,76.07,114.74,76.07,183.58v35.7c0,68.84-27.36,134.88-76.07,183.58l-219.31,188.66v-109.91l-.04-.04c0-28.48,12.3-55.6,33.72-74.42l177.99-156.26H0v-104.71h290.05l-171.55-150.61c-21.42-18.78-33.72-45.89-33.72-74.41v-110l219.31,188.83ZM995.18,259.68c0,28.48-12.26,55.6-33.69,74.42l-177.99,156.26h296.5v104.71h-290.05l171.54,150.6c21.38,18.78,33.69,45.9,33.69,74.42v110l-219.3-188.79c-48.71-48.7-76.08-114.74-76.08-183.58v-35.7c0-68.84,27.37-134.88,76.08-183.58l219.3-188.66v109.91ZM595.1,289.94l150.62-171.53c18.78-21.38,45.9-33.67,74.42-33.67h110l-188.79,219.29c-48.71,48.7-114.76,76.06-183.61,76.06h-35.7l-.04.04c-68.85,0-134.89-27.36-183.59-76.07L149.73,84.77h109.92c28.48,0,55.6,12.3,74.42,33.72l156.31,177.92V0h104.72v289.94Z"/>
|
|
4
|
+
</svg>
|
|
Binary file
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg viewBox="0 0 322 82" fill="currentColor" xmlns="http://www.w3.org/2000/svg" aria-label="Gladia">
|
|
2
|
+
<path d="M125.497 14.5989C128.431 14.5989 131.174 15.0301 133.728 15.8928C136.299 16.7383 138.594 17.9461 140.613 19.5168C142.632 21.0867 144.289 22.9511 145.583 25.1077C146.894 27.2642 147.748 29.6455 148.146 32.2512H138.362C137.965 30.8536 137.378 29.5935 136.602 28.4719C135.825 27.3506 134.884 26.4014 133.78 25.6252C132.676 24.8317 131.433 24.2364 130.053 23.8391C128.69 23.4246 127.214 23.218 125.626 23.218C122.762 23.2181 120.2 23.9343 117.94 25.3665C115.679 26.7987 113.892 28.904 112.581 31.6819C111.287 34.4426 110.64 37.8078 110.64 41.7766C110.64 45.7798 111.27 49.1706 112.529 51.9485C113.807 54.7264 115.567 56.8416 117.81 58.2903C120.053 59.7225 122.65 60.4387 125.601 60.4387C128.361 60.4387 130.752 59.8958 132.771 58.8088C134.79 57.721 136.343 56.211 137.43 54.2786C138.462 52.4728 139.012 50.4109 139.079 48.092H126.559V40.5862H148.533V68.3333H141.649L140.949 62.1213H140.665C138.801 64.3472 136.653 66.0645 134.22 67.2717C131.787 68.4625 128.896 69.0588 125.549 69.0588C120.683 69.0588 116.403 67.9629 112.71 65.7717C109.035 63.5624 106.163 60.4304 104.092 56.3752C102.021 52.3026 100.986 47.4707 100.986 41.8801C100.986 37.6006 101.607 33.7781 102.849 30.4133C104.092 27.0489 105.825 24.1928 108.051 21.8459C110.278 19.4826 112.875 17.6876 115.843 16.4622C118.81 15.2203 122.029 14.5989 125.497 14.5989ZM191.687 28.0588C194.016 28.0588 195.931 28.4548 197.433 29.2483C198.934 30.0255 200.126 30.9663 201.006 32.0706C201.885 33.1573 202.567 34.1841 203.05 35.1506H203.439V28.5764H212.834V68.3333H203.619V62.0696H203.05C202.567 63.0362 201.868 64.0628 200.953 65.1497C200.039 66.2192 198.831 67.1339 197.329 67.8928C195.829 68.6527 193.939 69.0325 191.661 69.0325C188.538 69.0325 185.743 68.2305 183.275 66.6252C180.807 65.0208 178.857 62.691 177.425 59.637C175.993 56.5821 175.277 52.872 175.277 48.5071C175.277 44.0891 176.001 40.3612 177.45 37.3245C178.917 34.2704 180.894 31.9659 183.378 30.4133C185.863 28.8426 188.633 28.0588 191.687 28.0588ZM258.017 68.3333H248.802V62.0696H248.233C247.749 63.0361 247.05 64.0629 246.136 65.1497C245.222 66.2193 244.013 67.1339 242.512 67.8928C241.01 68.6527 239.122 69.0325 236.844 69.0325C233.72 69.0324 230.924 68.2306 228.457 66.6252C225.99 65.0208 224.039 62.691 222.608 59.637C221.175 56.5821 220.459 52.872 220.459 48.5071C220.459 44.0892 221.183 40.3612 222.633 37.3245C224.1 34.2705 226.075 31.9659 228.561 30.4133C231.045 28.8426 233.815 28.0589 236.869 28.0588C239.199 28.0588 241.115 28.4547 242.616 29.2483C244.117 30.0254 245.308 30.9664 246.188 32.0706C247.068 33.1573 247.749 34.1841 248.233 35.1506H248.621V15.3235H258.017V68.3333ZM300.328 28.0588C302.658 28.0588 304.573 28.4549 306.074 29.2483C307.575 30.0255 308.767 30.9663 309.647 32.0706C310.527 33.1573 311.208 34.1841 311.692 35.1506H312.08V28.5764H321.476V68.3333H312.261V62.0696H311.692C311.208 63.0361 310.509 64.0629 309.595 65.1497C308.681 66.2193 307.472 67.1339 305.971 67.8928C304.469 68.6527 302.581 69.0325 300.303 69.0325C297.179 69.0325 294.383 68.2306 291.916 66.6252C289.449 65.0208 287.498 62.691 286.067 59.637C284.634 56.5821 283.918 52.872 283.918 48.5071C283.918 44.0891 284.642 40.3612 286.092 37.3245C287.559 34.2704 289.534 31.9659 292.02 30.4133C294.504 28.8426 297.274 28.0589 300.328 28.0588ZM166.079 56.9446C166.079 58.4287 166.303 59.4904 166.752 60.1282C167.2 60.7668 167.994 61.069 169.133 61.0344C169.754 61.0171 170.22 60.9828 170.53 60.9309C170.858 60.8617 171.153 60.7931 171.411 60.7239L172.964 67.8157C172.412 67.9878 171.722 68.1521 170.894 68.3079C170.083 68.4628 169.081 68.5574 167.891 68.592C164.094 68.6958 161.282 67.9021 159.452 66.2112C157.624 64.5202 156.709 61.9402 156.709 58.4719V15.3235H166.079V56.9446ZM276.643 68.3333H267.273V28.5764H276.643V68.3333ZM194.276 35.7454C192.188 35.7454 190.445 36.2893 189.047 37.3762C187.649 38.4632 186.596 39.965 185.889 41.8801C185.181 43.7952 184.828 45.9873 184.828 48.4543C184.828 50.9389 185.181 53.157 185.889 55.1067C186.613 57.0391 187.675 58.5662 189.072 59.6887C190.487 60.793 192.222 61.345 194.276 61.345C196.26 61.3449 197.95 60.8099 199.348 59.7395C200.745 58.6525 201.807 57.1427 202.532 55.2102C203.257 53.2778 203.619 51.0254 203.619 48.4543C203.619 45.8835 203.257 43.6489 202.532 41.7512C201.824 39.8534 200.772 38.3768 199.374 37.3245C197.994 36.2724 196.294 35.7454 194.276 35.7454ZM239.458 35.7454C237.37 35.7454 235.626 36.2893 234.229 37.3762C232.831 38.4632 231.779 39.9651 231.071 41.8801C230.364 43.7952 230.011 45.9872 230.011 48.4543C230.011 50.9389 230.364 53.1569 231.071 55.1067C231.797 57.0391 232.858 58.5662 234.256 59.6887C235.671 60.7928 237.405 61.345 239.458 61.345C241.443 61.3449 243.134 60.81 244.531 59.7395C245.929 58.6526 246.99 57.1425 247.714 55.2102C248.439 53.2778 248.802 51.0254 248.802 48.4543C248.802 45.8835 248.439 43.6489 247.714 41.7512C247.007 39.8534 245.955 38.3768 244.557 37.3245C243.177 36.2722 241.477 35.7454 239.458 35.7454ZM302.917 35.7454C300.829 35.7454 299.085 36.2893 297.688 37.3762C296.29 38.4632 295.238 39.9651 294.53 41.8801C293.823 43.7952 293.47 45.9872 293.47 48.4543C293.47 50.9389 293.823 53.1569 294.53 55.1067C295.256 57.039 296.317 58.5663 297.714 59.6887C299.129 60.793 300.864 61.345 302.917 61.345C304.901 61.3449 306.593 60.81 307.99 59.7395C309.388 58.6526 310.449 57.1425 311.173 55.2102C311.898 53.2778 312.261 51.0254 312.261 48.4543C312.261 45.8835 311.898 43.6489 311.173 41.7512C310.466 39.8534 309.414 38.3768 308.016 37.3245C306.636 36.2722 304.936 35.7454 302.917 35.7454ZM271.983 12.761C273.484 12.761 274.762 13.2616 275.815 14.2629C276.884 15.2459 277.418 16.4449 277.418 17.8596C277.418 19.258 276.884 20.457 275.815 21.4573C274.762 22.4413 273.484 22.9338 271.983 22.9338C270.499 22.9338 269.222 22.4412 268.153 21.4573C267.083 20.4569 266.548 19.2581 266.548 17.8596C266.548 16.4448 267.083 15.246 268.153 14.2629C269.222 13.2617 270.499 12.7611 271.983 12.761Z"/>
|
|
3
|
+
<path d="M42.8783 53.1389C48.1056 53.139 53.1197 55.2166 56.8177 58.9143L71.1429 75.5637H62.7972C60.6349 75.5636 58.5758 74.6324 57.1468 73.0061L45.2816 59.4934V82.0002H37.3314V59.9797L25.8949 73.0032C24.4689 74.6263 22.41 75.5598 20.2445 75.5598H11.8929L26.2279 58.9104C29.9259 55.2129 34.9401 53.135 40.1673 53.135H42.8783V53.1389ZM23.6126 25.7092C27.3105 29.407 29.388 34.4208 29.388 39.6477V42.3586C29.388 47.5855 27.3105 52.5994 23.6126 56.2971L6.96127 70.6213V62.2766L6.95834 62.2737C6.95834 60.1115 7.89247 58.0523 9.51889 56.6233L23.0326 44.759H0.52475V36.8088H22.5472L9.52182 25.3733C7.89561 23.9475 6.96136 21.889 6.96127 19.7239V11.3723L23.6126 25.7092ZM76.0843 19.717C76.0843 21.8793 75.1532 23.9385 73.5267 25.3674L60.013 37.2317H82.5247V45.1819H60.5023L73.5267 56.6165C75.1501 58.0423 76.0843 60.1015 76.0843 62.2668V70.6184L59.4339 56.2844C55.7359 52.5866 53.6576 47.573 53.6576 42.3459V39.635C53.6576 34.408 55.7359 29.3943 59.4339 25.6965L76.0843 11.3723V19.717ZM45.7083 22.0139L57.1439 8.99048C58.5698 7.36731 60.6288 6.43385 62.7943 6.43384H71.1458L56.8119 23.0833C53.1138 26.781 48.0989 28.8586 42.8714 28.8586H40.1605L40.1576 28.8616C34.9303 28.8615 29.9161 26.7839 26.2181 23.0862L11.8929 6.43677H20.2386C22.401 6.43682 24.46 7.37096 25.889 8.99731L37.7572 22.5061V0.000244141H45.7083V22.0139Z"/>
|
|
4
|
+
</svg>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg viewBox="0 0 82 82" fill="currentColor" xmlns="http://www.w3.org/2000/svg" aria-label="Gladia symbol">
|
|
2
|
+
<path d="M42.8783 53.1389C48.1056 53.139 53.1197 55.2166 56.8177 58.9143L71.1429 75.5637H62.7972C60.6349 75.5636 58.5758 74.6324 57.1468 73.0061L45.2816 59.4934V82.0002H37.3314V59.9797L25.8949 73.0032C24.4689 74.6263 22.41 75.5598 20.2445 75.5598H11.8929L26.2279 58.9104C29.9259 55.2129 34.9401 53.135 40.1673 53.135H42.8783V53.1389ZM23.6126 25.7092C27.3105 29.407 29.388 34.4208 29.388 39.6477V42.3586C29.388 47.5855 27.3105 52.5994 23.6126 56.2971L6.96127 70.6213V62.2766L6.95834 62.2737C6.95834 60.1115 7.89247 58.0523 9.51889 56.6233L23.0326 44.759H0.52475V36.8088H22.5472L9.52182 25.3733C7.89561 23.9475 6.96136 21.889 6.96127 19.7239V11.3723L23.6126 25.7092ZM76.0843 19.717C76.0843 21.8793 75.1532 23.9385 73.5267 25.3674L60.013 37.2317H82.5247V45.1819H60.5023L73.5267 56.6165C75.1501 58.0423 76.0843 60.1015 76.0843 62.2668V70.6184L59.4339 56.2844C55.7359 52.5866 53.6576 47.573 53.6576 42.3459V39.635C53.6576 34.408 55.7359 29.3943 59.4339 25.6965L76.0843 11.3723V19.717ZM45.7083 22.0139L57.1439 8.99048C58.5698 7.36731 60.6288 6.43385 62.7943 6.43384H71.1458L56.8119 23.0833C53.1138 26.781 48.0989 28.8586 42.8714 28.8586H40.1605L40.1576 28.8616C34.9303 28.8615 29.9161 26.7839 26.2181 23.0862L11.8929 6.43677H20.2386C22.401 6.43682 24.46 7.37096 25.889 8.99731L37.7572 22.5061V0.000244141H45.7083V22.0139Z"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# How it works
|
|
2
|
+
|
|
3
|
+
Every pipeline runs **three stages**, always in this order:
|
|
4
|
+
|
|
5
|
+
```text
|
|
6
|
+
text > [1] text_pre > split > [2] word > join > [3] text_post > text
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
| Stage | Operates on | Typical work |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| **1. Text pre** | Full string | Protect symbols, expand contractions/numbers, convert currency/degrees, casefold, remove punctuation |
|
|
12
|
+
| **2. Word** | One token | Replacements (`vs` → `versus`), skip emails |
|
|
13
|
+
| **3. Text post** | Full string | Restore placeholders, format times, collapse digits, whitespace |
|
|
14
|
+
|
|
15
|
+
This order is a hard constraint. Placeholder steps illustrate why: a decimal point is **protected** in stage 1 so `remove_symbols` cannot erase it, then **restored** in stage 3.
|
|
16
|
+
|
|
17
|
+
## Steps
|
|
18
|
+
|
|
19
|
+
A step is a small, stateless transform with a unique `name`. Steps register themselves via `@register_step`; presets reference those names.
|
|
20
|
+
|
|
21
|
+
See the full [step reference](reference/steps.md).
|
|
22
|
+
|
|
23
|
+
## Presets
|
|
24
|
+
|
|
25
|
+
A preset is a YAML file that lists which steps run in each stage and in what order. Published presets are **immutable** — new behavior means a new preset file (e.g. `gladia-4`).
|
|
26
|
+
|
|
27
|
+
Details and custom YAML: [Presets](presets.md).
|
|
28
|
+
|
|
29
|
+
## Languages
|
|
30
|
+
|
|
31
|
+
Language-specific data and behavior live under `normalization/languages/`. Unknown codes fall back to a language-agnostic default.
|
|
32
|
+
|
|
33
|
+
Details: [Languages](languages.md).
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# Contributing guide
|
|
2
|
+
|
|
3
|
+
Detailed reference for contributors. Read this before adding a step or language.
|
|
4
|
+
|
|
5
|
+
## Architecture at a glance
|
|
6
|
+
|
|
7
|
+
Every pipeline runs exactly **three stages**, always in this order:
|
|
8
|
+
|
|
9
|
+
1. **Text pre-processing** : full-text transforms before word splitting (placeholder protection, symbol conversion, contraction expansion, …)
|
|
10
|
+
2. **Word processing** : per-token transforms after splitting on spaces (replacements, filler removal, …)
|
|
11
|
+
3. **Text post-processing** : full-text cleanup after rejoining words (placeholder restoration, digit collapsing, …)
|
|
12
|
+
|
|
13
|
+
This ordering is a hard constraint - some steps depend on earlier steps having run. See [How it works](../concepts.md) for more detail.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Adding a new language
|
|
18
|
+
|
|
19
|
+
- Create `languages/{lang}/` with `operators.py`, `replacements.py`, `__init__.py`
|
|
20
|
+
- Put all word-level substitutions in `replacements.py`; do not add inline entries in `operators.py`
|
|
21
|
+
- Instantiate a `LanguageConfig` in `operators.py`, filling in all required fields and any optional dict fields your language needs (`time_words`, `sentence_replacements`, etc.)
|
|
22
|
+
- Subclass `LanguageOperators`, overriding only methods where the _algorithm_ differs (not just the data)
|
|
23
|
+
- If the language has digit words, populate `digit_words` in `LanguageConfig`
|
|
24
|
+
- If the language uses spoken time patterns, populate `time_words` with all needed word-to-digit mappings; if it also uses compound minute expressions (e.g. "twenty-one"), override `get_compound_minutes()` - do **not** put this in config
|
|
25
|
+
- If number expansion is needed and the algorithm is complex, implement it in a `number_normalizer.py` file and override `expand_written_numbers`; otherwise do not create the file
|
|
26
|
+
- Decorate the class with `@register_language`
|
|
27
|
+
- Add one import to `languages/__init__.py`
|
|
28
|
+
- Add tests in `tests/unit/languages/`
|
|
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
|
+
|
|
31
|
+
### Language data vs. language behavior
|
|
32
|
+
|
|
33
|
+
This is the central design rule. Ask: "does the _logic_ change by language, or just the _values_?"
|
|
34
|
+
|
|
35
|
+
**`LanguageConfig` (data)** : everything that can be expressed as a value: strings, lists, dicts. Separator characters, currency words, filler words, digit words, number words, time words, sentence replacements. Optional fields default to `None`; steps that read them skip gracefully when `None`.
|
|
36
|
+
|
|
37
|
+
**`LanguageOperators` (behavior)** : only methods where the _algorithm itself_ varies by language. Examples: `expand_contractions`, `expand_written_numbers`, `normalize_numeric_time_formats`, `get_compound_minutes`. If the algorithm is generic and only the _data_ differs, put the data in `LanguageConfig` and the algorithm in the step - not in the operator.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Adding a new step
|
|
42
|
+
|
|
43
|
+
- Add the class to the appropriate file in `steps/text/` or `steps/word/`
|
|
44
|
+
- Set a unique `name` class attribute
|
|
45
|
+
- Decorate with `@register_step`
|
|
46
|
+
- Add one import to `steps/text/__init__.py` or `steps/word/__init__.py`
|
|
47
|
+
- Place the algorithm in `__call__`; read language data from `operators.config.*`; call operator methods only for genuinely behavioral differences
|
|
48
|
+
- If the step reads an optional `LanguageConfig` field, guard with `if operators.config.field is None: return text`
|
|
49
|
+
- Add unit tests in `tests/unit/steps/`
|
|
50
|
+
- If it involves placeholder protection, add both protect and restore to `steps/text/placeholders.py` and update `pipeline/base.py`'s `validate()` accordingly
|
|
51
|
+
- Add the step name to relevant preset YAMLs if needed (new preset version if existing presets are affected)
|
|
52
|
+
- If you added or changed the class docstring, run `uv run scripts/generate_step_docs.py` to regenerate `docs/reference/steps.md`
|
|
53
|
+
|
|
54
|
+
### Choosing a base class
|
|
55
|
+
|
|
56
|
+
Pick the narrowest one that fits your step.
|
|
57
|
+
|
|
58
|
+
**`WordStep`** : use when your transformation operates on a single token in isolation, with no knowledge of neighboring words. This is the only base class for Stage 2 steps.
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
@register_step
|
|
62
|
+
class MyWordStep(WordStep):
|
|
63
|
+
name = "my_word_step"
|
|
64
|
+
|
|
65
|
+
def __call__(self, word: str, operators: LanguageOperators) -> str: ...
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**`TextStep`** : the general-purpose base for Stage 1 and Stage 3. Use it when your transformation needs to see the full string, or when none of the more specific bases below fit.
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
@register_step
|
|
72
|
+
class MyTextStep(TextStep):
|
|
73
|
+
name = "my_text_step"
|
|
74
|
+
|
|
75
|
+
def __call__(self, text: str, operators: LanguageOperators) -> str: ...
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**`ProtectStep`** : a specialization of `TextStep` for replacing a character with a placeholder token. Implement `_pattern`, which returns a compiled regex with **exactly two capture groups** (what comes before and after the character being replaced). The `__call__` is fixed: it applies the pattern as `\1{placeholder}\2`.
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
@register_step
|
|
82
|
+
class MyProtectStep(ProtectStep):
|
|
83
|
+
name = "my_protect_step"
|
|
84
|
+
placeholder = ProtectPlaceholder.MY_PLACEHOLDER
|
|
85
|
+
|
|
86
|
+
def _pattern(self, operators: LanguageOperators) -> re.Pattern:
|
|
87
|
+
return re.compile(r"(\d+)X(\d+)") # two capture groups required
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
> Use `ProtectStep` when: one regex pattern maps to exactly one placeholder substitution.
|
|
91
|
+
|
|
92
|
+
> Use `TextStep` directly instead when: a single pass must protect two different symbols, the replacement needs to absorb surrounding whitespace with `\s*`, or the replacement is a per-match function rather than a fixed template.
|
|
93
|
+
|
|
94
|
+
**`RestoreStep`** : a specialization of `TextStep` for restoring a placeholder back to a string. Implement `_replacement`, which returns the string to substitute in. The `__call__` does a plain `str.replace` of the placeholder (and its case-folded form).
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
@register_step
|
|
98
|
+
class MyRestoreStep(RestoreStep):
|
|
99
|
+
name = "my_restore_step"
|
|
100
|
+
placeholder = ProtectPlaceholder.MY_PLACEHOLDER
|
|
101
|
+
|
|
102
|
+
def _replacement(self, operators: LanguageOperators) -> str:
|
|
103
|
+
return operators.config.some_word or " "
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
> Use `RestoreStep` when: restoration is a straight token swap with no surrounding whitespace to absorb and no additional logic needed.
|
|
107
|
+
|
|
108
|
+
> Use `TextStep` directly instead when: the placeholder was inserted with spaces around it (requiring `re.sub` with `\s*` to avoid double spaces), the marker should be deleted entirely rather than replaced, or post-replacement cleanup is needed.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Writing tests
|
|
113
|
+
|
|
114
|
+
### Unit tests for a step
|
|
115
|
+
|
|
116
|
+
Unit tests live under `tests/unit/steps/text/` or `tests/unit/steps/word/`, mirroring the step file structure.
|
|
117
|
+
|
|
118
|
+
The `tests/unit/steps/text/conftest.py` provides two fixtures and a helper:
|
|
119
|
+
|
|
120
|
+
- `operators` : a bare `LanguageOperators()` instance (language-agnostic)
|
|
121
|
+
- `english_operators` : an `EnglishOperators()` instance
|
|
122
|
+
- `assert_text_step_registered(step_cls)` : verifies the step is in the registry under its name
|
|
123
|
+
|
|
124
|
+
Every test file for a step should at minimum:
|
|
125
|
+
|
|
126
|
+
1. Assert the step is registered.
|
|
127
|
+
2. Instantiate the step with `MyStep()` and call it directly: `MyStep()(text, operators)`.
|
|
128
|
+
3. Mutate `operators.config` fields in-place to cover different language configurations without creating a full language.
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
# tests/unit/steps/text/my_step_test.py
|
|
132
|
+
from normalization.languages.base import LanguageOperators
|
|
133
|
+
from normalization.steps.text.my_module import MyStep
|
|
134
|
+
|
|
135
|
+
from .conftest import assert_text_step_registered
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def test_step_is_registered():
|
|
139
|
+
assert_text_step_registered(MyStep)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def test_my_step_basic(operators: LanguageOperators):
|
|
143
|
+
result = MyStep()("some input", operators)
|
|
144
|
+
assert result == "expected output"
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def test_my_step_with_config(operators: LanguageOperators):
|
|
148
|
+
operators.config.some_field = "custom_value"
|
|
149
|
+
result = MyStep()("some input", operators)
|
|
150
|
+
assert result == "expected output with custom value"
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def test_my_step_with_english(english_operators):
|
|
154
|
+
result = MyStep()("some input", english_operators)
|
|
155
|
+
assert result == "english-specific output"
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### E2E tests for a preset
|
|
159
|
+
|
|
160
|
+
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/`.
|
|
161
|
+
|
|
162
|
+
**Directory structure** : one folder per preset, one CSV per language:
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
tests/e2e/files/
|
|
166
|
+
gladia-3/
|
|
167
|
+
default.csv
|
|
168
|
+
da.csv
|
|
169
|
+
de.csv
|
|
170
|
+
en.csv
|
|
171
|
+
es.csv
|
|
172
|
+
fi.csv
|
|
173
|
+
fr.csv
|
|
174
|
+
it.csv
|
|
175
|
+
nl.csv
|
|
176
|
+
sv.csv
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**CSV format** : two columns (`input,expected`), no quoting needed unless the value contains a comma:
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
input,expected
|
|
183
|
+
"$1,000,000",1000000 dollars
|
|
184
|
+
hello world,hello world
|
|
185
|
+
```
|
|
186
|
+
> The language is derived from the filename (e.g. `fr.csv` → language code `fr`). Use `default.csv` for the language-agnostic fallback.
|
|
187
|
+
|
|
188
|
+
**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.
|
|
189
|
+
|
|
190
|
+
**Registering a new preset** : add a block to `normalization_test.py` following the existing pattern:
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
_MY_PRESET_DIR = _FILES_DIR / "my-preset"
|
|
194
|
+
_MY_PRESET_BY_LANGUAGE = _discover_preset_tests(_MY_PRESET_DIR)
|
|
195
|
+
_MY_PRESET_PIPELINES: dict[str, NormalizationPipeline] = {}
|
|
196
|
+
|
|
197
|
+
for _language in sorted(_MY_PRESET_BY_LANGUAGE):
|
|
198
|
+
globals()[f"test_my_preset_{_language}"] = _make_test(
|
|
199
|
+
"my-preset", _language, _MY_PRESET_BY_LANGUAGE[_language], _MY_PRESET_PIPELINES
|
|
200
|
+
)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
> Pipelines are cached per language to avoid reloading for each parametrized case.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## Key design rules
|
|
208
|
+
|
|
209
|
+
- **Data vs. behavior**: if only the _values_ change by language, put them in `LanguageConfig`. If the _algorithm_ changes, override a method in `LanguageOperators`.
|
|
210
|
+
- **Steps are language-agnostic**: a step must not contain any language-specific logic or string literals. Read from `operators.config.*` or call `operators.method()`.
|
|
211
|
+
- **Presets are immutable**: never modify a published preset YAML - new behavior means a new preset file.
|
|
212
|
+
- **Placeholder pairs**: every `protect_*` step in Stage 1 must have a matching `restore_*` in Stage 3. The pipeline validates this at load time.
|
|
213
|
+
- **Language folders are self-contained**: everything specific to a language lives inside its folder. Helpers used only by one language (e.g. `number_normalizer.py`) go in that language's folder, not in `steps/`.
|