gladia-normalization 0.1.0__py3-none-any.whl
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.1.0.dist-info/METADATA +210 -0
- gladia_normalization-0.1.0.dist-info/RECORD +72 -0
- gladia_normalization-0.1.0.dist-info/WHEEL +4 -0
- gladia_normalization-0.1.0.dist-info/licenses/LICENSE +21 -0
- normalization/__init__.py +4 -0
- normalization/constants/__init__.py +3 -0
- normalization/constants/protectors.py +24 -0
- normalization/languages/__init__.py +7 -0
- normalization/languages/base/__init__.py +7 -0
- normalization/languages/base/language_config.py +83 -0
- normalization/languages/base/language_operator.py +65 -0
- normalization/languages/english/__init__.py +7 -0
- normalization/languages/english/number_normalizer.py +433 -0
- normalization/languages/english/operators.py +199 -0
- normalization/languages/english/replacements.py +1774 -0
- normalization/languages/english/sentence_replacements.py +3 -0
- normalization/languages/french/__init__.py +7 -0
- normalization/languages/french/operators.py +38 -0
- normalization/languages/french/replacements.py +1 -0
- normalization/languages/registry.py +17 -0
- normalization/pipeline/__init__.py +0 -0
- normalization/pipeline/base.py +120 -0
- normalization/pipeline/loader.py +70 -0
- normalization/pipeline/replacer.py +38 -0
- normalization/presets/gladia-3.yaml +119 -0
- normalization/steps/__init__.py +4 -0
- normalization/steps/base/__init__.py +6 -0
- normalization/steps/base/protect_step.py +24 -0
- normalization/steps/base/restore_step.py +23 -0
- normalization/steps/base/text_step.py +11 -0
- normalization/steps/base/word_step.py +11 -0
- normalization/steps/registry.py +26 -0
- normalization/steps/text/__init__.py +79 -0
- normalization/steps/text/apply_sentence_level_replacements.py +29 -0
- normalization/steps/text/casefold_text.py +13 -0
- normalization/steps/text/convert_comparison_operators_to_words.py +26 -0
- normalization/steps/text/convert_decimal_periods_to_decimal_word.py +30 -0
- normalization/steps/text/convert_degree_symbols_to_words.py +26 -0
- normalization/steps/text/convert_digit_word_sequences_to_digits.py +41 -0
- normalization/steps/text/convert_dots_to_words_in_technical_contexts.py +33 -0
- normalization/steps/text/convert_oclock_to_numeric_time.py +34 -0
- normalization/steps/text/convert_roman_numerals_to_digits.py +41 -0
- normalization/steps/text/convert_word_based_time_patterns.py +70 -0
- normalization/steps/text/expand_alphanumeric_codes.py +64 -0
- normalization/steps/text/expand_contractions.py +16 -0
- normalization/steps/text/expand_written_numbers_to_digits.py +13 -0
- normalization/steps/text/expand_www_abbreviation.py +15 -0
- normalization/steps/text/fix_ampm_letter_spacing.py +25 -0
- normalization/steps/text/fix_dot_adjacent_number_words.py +37 -0
- normalization/steps/text/fix_one_word_in_numeric_contexts.py +16 -0
- normalization/steps/text/fix_version_number_v_prefix.py +15 -0
- normalization/steps/text/format_time_patterns_with_ampm.py +53 -0
- normalization/steps/text/normalize_numeric_time_formats.py +16 -0
- normalization/steps/text/normalize_punctuation_between_number_words.py +30 -0
- normalization/steps/text/placeholders.py +367 -0
- normalization/steps/text/protect_plus_word_before_digit_words.py +37 -0
- normalization/steps/text/remove_acronym_periods.py +17 -0
- normalization/steps/text/remove_diacritics.py +40 -0
- normalization/steps/text/remove_filler_words.py +19 -0
- normalization/steps/text/remove_hash_before_numbers.py +15 -0
- normalization/steps/text/remove_non_numeric_trailing_dots.py +15 -0
- normalization/steps/text/remove_spaces_between_adjacent_digits.py +54 -0
- normalization/steps/text/remove_standalone_currency_symbols.py +35 -0
- normalization/steps/text/remove_symbols.py +24 -0
- normalization/steps/text/remove_thousand_separators.py +24 -0
- normalization/steps/text/remove_trailing_apostrophe_space.py +15 -0
- normalization/steps/text/remove_trailing_dot_word_from_emails.py +22 -0
- normalization/steps/text/remove_trailing_period.py +15 -0
- normalization/steps/text/remove_zero_minutes_from_time.py +30 -0
- normalization/steps/text/replace_currency.py +31 -0
- normalization/steps/word/__init__.py +3 -0
- normalization/steps/word/apply_word_replacements.py +33 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gladia-normalization
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Normalize speech-to-text output for fair Word Error Rate (WER) comparison
|
|
5
|
+
Project-URL: Homepage, https://github.com/gladiaio/normalization
|
|
6
|
+
Project-URL: Repository, https://github.com/gladiaio/normalization
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/gladiaio/normalization/issues
|
|
8
|
+
Author-email: Gladia <support@gladia.io>
|
|
9
|
+
License: MIT License
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2026 Gladia
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Keywords: ASR,STT,WER,benchmark,normalization,speech-to-text,transcription
|
|
32
|
+
Classifier: Development Status :: 4 - Beta
|
|
33
|
+
Classifier: Intended Audience :: Developers
|
|
34
|
+
Classifier: Intended Audience :: Science/Research
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Programming Language :: Python :: 3
|
|
37
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
38
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
39
|
+
Requires-Python: >=3.10
|
|
40
|
+
Requires-Dist: contractions>=0.1.73
|
|
41
|
+
Requires-Dist: pyyaml>=6.0.3
|
|
42
|
+
Description-Content-Type: text/markdown
|
|
43
|
+
|
|
44
|
+
<p align="center">
|
|
45
|
+
<h1 align="center">Normalization</h1>
|
|
46
|
+
<p align="center">
|
|
47
|
+
A lightweight library for normalizing speech transcripts before computing WER.
|
|
48
|
+
<br />
|
|
49
|
+
<a href="#quick-start">Quick Start</a> · <a href="docs/steps.md">Step Reference</a> · <a href="CONTRIBUTING.md">Contributing</a>
|
|
50
|
+
</p>
|
|
51
|
+
</p>
|
|
52
|
+
|
|
53
|
+
<p align="center">
|
|
54
|
+
<img src="https://img.shields.io/pypi/v/gladia_normalization?style=flat-square" alt="PyPI version" />
|
|
55
|
+
<img src="https://img.shields.io/pypi/pyversions/gladia_normalization?style=flat-square" alt="Python versions" />
|
|
56
|
+
<img src="https://img.shields.io/pypi/l/gladia_normalization?style=flat-square" alt="License" />
|
|
57
|
+
</p>
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Why normalization matters
|
|
62
|
+
|
|
63
|
+
Word Error Rate (WER) is the standard metric for evaluating speech-to-text systems. But WER operates on raw strings — it has no notion of meaning. Two transcriptions that say the same thing in different surface forms get penalized as errors:
|
|
64
|
+
|
|
65
|
+
| Ground truth | STT output | Match without normalization |
|
|
66
|
+
| ------------ | ------------------- | --------------------------- |
|
|
67
|
+
| It's $50 | it is fifty dollars | 0/3 words match |
|
|
68
|
+
| 3:00 PM | 3 pm | 0/2 words match |
|
|
69
|
+
| Mr. Smith | mister smith | 0/2 words match |
|
|
70
|
+
|
|
71
|
+
These aren't transcription errors — they're formatting differences. Without normalization, WER scores become unreliable and comparisons across engines are meaningless.
|
|
72
|
+
|
|
73
|
+
`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.
|
|
74
|
+
|
|
75
|
+
## What it does
|
|
76
|
+
|
|
77
|
+
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.
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
Input: "It's $50.9 at 3:00PM — y'know, roughly."
|
|
81
|
+
Output: "it is 50 point 9 dollars at 3 pm you know roughly"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The pipeline is deterministic, language-aware, and fully defined in YAML — run the same preset and get the same output every time.
|
|
85
|
+
|
|
86
|
+
## Quick start
|
|
87
|
+
|
|
88
|
+
### Installation
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pip install gladia-normalization
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
<details>
|
|
95
|
+
<summary>Install from source</summary>
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
git clone https://github.com/gladiaio/normalization.git
|
|
99
|
+
cd normalization
|
|
100
|
+
uv sync
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
</details>
|
|
104
|
+
|
|
105
|
+
### Usage
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from normalization import load_pipeline
|
|
109
|
+
|
|
110
|
+
# Load a built-in preset by name
|
|
111
|
+
pipeline = load_pipeline("gladia-3", language="en")
|
|
112
|
+
|
|
113
|
+
pipeline.normalize("It's $50 at 3:00PM")
|
|
114
|
+
# => "it is 50 dollars at 3 pm"
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## How it works
|
|
118
|
+
|
|
119
|
+
Every pipeline runs exactly **three stages**, always in this order:
|
|
120
|
+
|
|
121
|
+
- **Stage 1 — Text pre-processing**: Full-text transforms: protect symbols, expand contractions, convert numbers, casefold, remove symbols
|
|
122
|
+
- **Stage 2 — Word processing**: Per-token transforms: word replacements, filler removal
|
|
123
|
+
- **Stage 3 — Text post-processing**: Full-text cleanup: restore placeholders, collapse digits, format time patterns, normalize whitespace
|
|
124
|
+
|
|
125
|
+
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).
|
|
126
|
+
|
|
127
|
+
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](docs/steps.md) for every available step.
|
|
128
|
+
|
|
129
|
+
## Supported languages
|
|
130
|
+
|
|
131
|
+
| Code | Language |
|
|
132
|
+
| ---- | -------------- |
|
|
133
|
+
| `en` | English |
|
|
134
|
+
| `fr` | French (alpha) |
|
|
135
|
+
|
|
136
|
+
Unsupported language codes fall back to a safe default that applies language-independent normalization only.
|
|
137
|
+
|
|
138
|
+
Adding a new language is self-contained — create a folder, register it with a decorator, done. See [Contributing](#adding-a-new-language).
|
|
139
|
+
|
|
140
|
+
## Custom presets
|
|
141
|
+
|
|
142
|
+
A preset is a YAML file that declares which steps run in each stage and in what order.
|
|
143
|
+
|
|
144
|
+
```yaml
|
|
145
|
+
name: my-preset-v1
|
|
146
|
+
|
|
147
|
+
stages:
|
|
148
|
+
text_pre:
|
|
149
|
+
- protect_email_symbols
|
|
150
|
+
- expand_contractions
|
|
151
|
+
- casefold_text
|
|
152
|
+
- remove_symbols
|
|
153
|
+
- remove_diacritics
|
|
154
|
+
- normalize_whitespace
|
|
155
|
+
|
|
156
|
+
word:
|
|
157
|
+
- apply_word_replacements
|
|
158
|
+
|
|
159
|
+
text_post:
|
|
160
|
+
- restore_email_at_symbol_with_word
|
|
161
|
+
- restore_email_dot_symbol_with_word
|
|
162
|
+
- normalize_whitespace
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
_Load from your custom configuration:_
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from normalization import load_pipeline
|
|
169
|
+
|
|
170
|
+
pipeline = load_pipeline("path/to/my-custom-configuration.yaml", language="en")
|
|
171
|
+
result = pipeline.normalize("some transcription text")
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Inspect a loaded pipeline:
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
pipeline.describe()
|
|
178
|
+
# {'name': 'my-preset-v1', 'language': 'en', 'text_pre_steps': [...], ...}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
**Preset rules:**
|
|
182
|
+
|
|
183
|
+
- Step names must match the `name` attribute of a registered step class.
|
|
184
|
+
- Every `protect_*` step in `text_pre` requires a matching `restore_*` in `text_post`. The pipeline validates this at load time.
|
|
185
|
+
- List order is execution order.
|
|
186
|
+
- Published presets are immutable — new behavior means a new file.
|
|
187
|
+
|
|
188
|
+
## Contributing
|
|
189
|
+
|
|
190
|
+
Bug reports, new steps, and new language support are all welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for the full guide — including how to add steps, add languages, write tests, and the commit style we follow.
|
|
191
|
+
|
|
192
|
+
### Development
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
uv run pre-commit install --install-hooks # install hooks once after cloning
|
|
196
|
+
uv run pytest # run tests
|
|
197
|
+
uv run ruff check . # lint
|
|
198
|
+
uv run ruff format . # format
|
|
199
|
+
uv run ty check # type-check
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## About
|
|
203
|
+
|
|
204
|
+
`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.
|
|
205
|
+
|
|
206
|
+
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.
|
|
207
|
+
|
|
208
|
+
## License
|
|
209
|
+
|
|
210
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
normalization/__init__.py,sha256=zdl65g57PQ46K27QZ7vKDIIFSBuYdU32OLhvSHqDQQo,172
|
|
2
|
+
normalization/constants/__init__.py,sha256=LaLsSAOAFmUpeVNgdWTQUUGG_9t1cfJdMrUT9-GS50o,77
|
|
3
|
+
normalization/constants/protectors.py,sha256=qr3nz9ZeQKGRRW3kGVkQRQ4AoeN0RUCiTH8SDvaTBqo,634
|
|
4
|
+
normalization/languages/__init__.py,sha256=FvFhkKITPX8C-bNc2XDr_gFWbTk6i6C3F-yDXhJnL-s,225
|
|
5
|
+
normalization/languages/registry.py,sha256=sBPYUN3YsdqTgp_TBw_Ej9zqkxVbFSJ5wye929VpmQA,486
|
|
6
|
+
normalization/languages/base/__init__.py,sha256=tzesYno8yaYnIW97EWa0WltptllZiDS8HjYDWHaXvCM,211
|
|
7
|
+
normalization/languages/base/language_config.py,sha256=nLq2caBR74l2Z16DP6dXBvrXqYB5Rt80dX_edCOocRs,4506
|
|
8
|
+
normalization/languages/base/language_operator.py,sha256=yHFljKlBuMXUU77LHqjRnNlELELfFR--p8Lg33qeijA,2606
|
|
9
|
+
normalization/languages/english/__init__.py,sha256=3VWLoKVIip3xs8GOh1XQZYwcs1Wj_xfYJjfnd4lLmoU,154
|
|
10
|
+
normalization/languages/english/number_normalizer.py,sha256=TJUu0Ox3c1dTOfP24slpaYnFv3dpHPw8CnB0IDHEPMY,16548
|
|
11
|
+
normalization/languages/english/operators.py,sha256=QrxH3gaiGqEDbr3bp8NwWrTJQmE2MVpGnNN4dkXxoaA,6010
|
|
12
|
+
normalization/languages/english/replacements.py,sha256=YnFbmf2fSFEoCwTxOK8t8cFM_Tu9iGt-Guz4t8PcmfU,56948
|
|
13
|
+
normalization/languages/english/sentence_replacements.py,sha256=a6BjR-6g_e-VlqEm6qjM3G8rd2Mvj8A-49JS5nG4MOg,79
|
|
14
|
+
normalization/languages/french/__init__.py,sha256=Hedb8h5R5ZQFHrMI3zlUQwdo-JG4fkV9SoV0A5LRZ0A,150
|
|
15
|
+
normalization/languages/french/operators.py,sha256=qiJ9adTfIyAxjOtQgaYViTNwdD2z_wJNpU3D7OiKWV8,931
|
|
16
|
+
normalization/languages/french/replacements.py,sha256=LEDLedHCA1NyJHfOecHpmKmFmfLn6rL8VWUgeE-LsJI,41
|
|
17
|
+
normalization/pipeline/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
+
normalization/pipeline/base.py,sha256=jfJz4URgE2IjG4gIkuuE0r8V5ZnOgxlzr91rbIsB6HM,4367
|
|
19
|
+
normalization/pipeline/loader.py,sha256=hO435AIc9JpWbKLCJ1e2_0MVgbJAt44Du9rqJz2L2Qs,2469
|
|
20
|
+
normalization/pipeline/replacer.py,sha256=Q8b_1p9PDe4-hN3-MtuL3AR8pm7UwhOHL1qdtBFZeok,1180
|
|
21
|
+
normalization/presets/gladia-3.yaml,sha256=kb6Fon4xSwvpdZojYBsiwmM8mGnlsqczZIjKQ4EkGx4,5237
|
|
22
|
+
normalization/steps/__init__.py,sha256=uc6fyiok2Mybb9gsLars8AHP8wrN90oposIkfUIpiJg,114
|
|
23
|
+
normalization/steps/registry.py,sha256=fIQ2bggz8z3WV4ICcr3GNn2zTfEVCQAkfO7_5sQa350,791
|
|
24
|
+
normalization/steps/base/__init__.py,sha256=WkkEEd-5ODGGVAIwRgVD4fHf5_34__Gd5cZJCVc36wE,206
|
|
25
|
+
normalization/steps/base/protect_step.py,sha256=IHgfUGgmn0NT7h3JHKhSXFG5bamX-exy1MmHUNK8rZE,914
|
|
26
|
+
normalization/steps/base/restore_step.py,sha256=sMGQ0aeUStW08c1-LBDO7BluJCzM0pQGcgO-uBy9-ok,713
|
|
27
|
+
normalization/steps/base/text_step.py,sha256=HGP5PN5tDdOXQP3CycUDds9fJmEicn_vZIVRZfdbk-I,268
|
|
28
|
+
normalization/steps/base/word_step.py,sha256=SrUrLnqH0rcPomDfUT6oHUzfIWrKFnzu9GslaxAw6Nw,267
|
|
29
|
+
normalization/steps/text/__init__.py,sha256=oDxkd9Uigskeo6x0rENS7ruSq8Unx5_XOetyha1i0EQ,2651
|
|
30
|
+
normalization/steps/text/apply_sentence_level_replacements.py,sha256=UBXMoJIw0rOu9ohagcQ9qq-utHbkU5THqG3M0X2_N2k,1124
|
|
31
|
+
normalization/steps/text/casefold_text.py,sha256=_zuCt3eyrznNglFyN4PINLuxXypkTugSAAuSOBcvlZI,394
|
|
32
|
+
normalization/steps/text/convert_comparison_operators_to_words.py,sha256=p0qvP1LRRO7sWU4tMBOYwesrPUxvOhJBDGc0_1icbWU,959
|
|
33
|
+
normalization/steps/text/convert_decimal_periods_to_decimal_word.py,sha256=mzky4HunuyJUiE6cNtcRCICjVmgOXWIbWqLR5VG7tSU,1042
|
|
34
|
+
normalization/steps/text/convert_degree_symbols_to_words.py,sha256=NCWkQ7YzdFrw00R4Sqt9kajc39TyDaUO67pzAzwWbp0,969
|
|
35
|
+
normalization/steps/text/convert_digit_word_sequences_to_digits.py,sha256=PioJnhmkbWI2T87qzDUmUjTpmTu3SvHkO7sTZ5vg-pM,1455
|
|
36
|
+
normalization/steps/text/convert_dots_to_words_in_technical_contexts.py,sha256=dp4WX3c_RU7LTDoL6xTR31e8bUSWqBsY2jOcsprRqH4,1617
|
|
37
|
+
normalization/steps/text/convert_oclock_to_numeric_time.py,sha256=N5-x5y5drZTNvmeIb5f2lsxqp2Ww-Y_jUnTQDx3ol-Q,1360
|
|
38
|
+
normalization/steps/text/convert_roman_numerals_to_digits.py,sha256=qohlNtzHGEDKs1eESNb2jYGJ880NDllfLv7BkwmhxFw,1240
|
|
39
|
+
normalization/steps/text/convert_word_based_time_patterns.py,sha256=JOM4Bq1vNS7mLug6Zt0s9gSU1thq_n4oDuDCxeLFEdU,2744
|
|
40
|
+
normalization/steps/text/expand_alphanumeric_codes.py,sha256=zPAALl2eI4-8AYW91Vb41vy4euV7q0KFG9DZTRsqg3c,2056
|
|
41
|
+
normalization/steps/text/expand_contractions.py,sha256=1-BLknYNUnwh_p_mchj0GHEe8APps7C-fx-omZC9Vy8,495
|
|
42
|
+
normalization/steps/text/expand_written_numbers_to_digits.py,sha256=ZbVkKrAUWqA-YVG6amljaBV1QQcQ2yC28JfVGWj94zU,529
|
|
43
|
+
normalization/steps/text/expand_www_abbreviation.py,sha256=8AHilw63iPdkljHQRFqofiPUlexNCQhxhILZlq67b6Y,447
|
|
44
|
+
normalization/steps/text/fix_ampm_letter_spacing.py,sha256=moGuFlGjKNxnJw_wAfi24lHXc6it8Zvani-2iT4Z25M,826
|
|
45
|
+
normalization/steps/text/fix_dot_adjacent_number_words.py,sha256=TAOzRI8gGnEMbOcEZDgCqErKFzY0v6EYWFY_FAcAxQY,1273
|
|
46
|
+
normalization/steps/text/fix_one_word_in_numeric_contexts.py,sha256=YeSN2OTSk5YXcIFaoT7HuskM8pKL5ezvn69zjC6ihxk,563
|
|
47
|
+
normalization/steps/text/fix_version_number_v_prefix.py,sha256=17EiZ0GHkfWcaPpSbg8ZOtOZAPIxBZrw3WC3uJHROns,492
|
|
48
|
+
normalization/steps/text/format_time_patterns_with_ampm.py,sha256=s2-jspyet9UMLCAnqc4RFDqU4oCj7psauwrfVAw3LlM,1663
|
|
49
|
+
normalization/steps/text/normalize_numeric_time_formats.py,sha256=Hq7b7VfqPEXcfVI0pho18ilwqDddvC2oJI7sCUPXxOI,558
|
|
50
|
+
normalization/steps/text/normalize_punctuation_between_number_words.py,sha256=j7Q_PKWHPa623b-icwGZMsfSz4Hawvy9cMH8XVaSDB0,1084
|
|
51
|
+
normalization/steps/text/placeholders.py,sha256=YFwpVzM_HPsoydOK5tJkVHlIR7na-YtCuz4d-BaDnjc,12866
|
|
52
|
+
normalization/steps/text/protect_plus_word_before_digit_words.py,sha256=JvUfZErQxiIk3s1lPjPxG76E3cc-5XyKvhdFxOPqngc,1282
|
|
53
|
+
normalization/steps/text/remove_acronym_periods.py,sha256=9VbT5Bwyzka2CQJ-Rdee9ENcZLuStbwiT0Q04zwiRJ4,563
|
|
54
|
+
normalization/steps/text/remove_diacritics.py,sha256=nzmirS5rOsB-smfu4mz8k9w8_364k6Oo7TfFk--52C8,1018
|
|
55
|
+
normalization/steps/text/remove_filler_words.py,sha256=siq2B6y81qE7WKxL_v5htnZmXryNCeBnXsgtuHsJ8AI,660
|
|
56
|
+
normalization/steps/text/remove_hash_before_numbers.py,sha256=8ZsjmBwF1rtcWqxzf1IgrA9yX_Yh0hbV8E7VuMzYnM4,445
|
|
57
|
+
normalization/steps/text/remove_non_numeric_trailing_dots.py,sha256=EdEYf61UubucIpIqjuaXaff0u2hXw2xF1yWUk33OiTg,487
|
|
58
|
+
normalization/steps/text/remove_spaces_between_adjacent_digits.py,sha256=TTr4vOGfNhEnnhyI7yP7orpw1b7rQO-eSli16A1nHVk,1897
|
|
59
|
+
normalization/steps/text/remove_standalone_currency_symbols.py,sha256=YufJBJn1Ku95l930CzRl0XDvjX86ZCAVJSyQeIZtSqI,1241
|
|
60
|
+
normalization/steps/text/remove_symbols.py,sha256=QOSLZ1WSsBOBgm54SZU2rk8dSEj0qYOpbHIow7KO-yc,790
|
|
61
|
+
normalization/steps/text/remove_thousand_separators.py,sha256=RlCF3lg0S9Ye4kDJin4VcSxShaq9soesreo9xkI7ryU,865
|
|
62
|
+
normalization/steps/text/remove_trailing_apostrophe_space.py,sha256=FXC8clbxGX0wA2ozteu2DJpF1vEwJTqZCTNSBML7KGs,455
|
|
63
|
+
normalization/steps/text/remove_trailing_dot_word_from_emails.py,sha256=HzhUj3mbG3KZ-rbST5gM59jUqrxvSHgHDoNL3z1S_Js,680
|
|
64
|
+
normalization/steps/text/remove_trailing_period.py,sha256=Xpo1kFx7xvISHn0SVwU8N6PgxFPEud6Q7XCzpELxZnU,430
|
|
65
|
+
normalization/steps/text/remove_zero_minutes_from_time.py,sha256=ek803Bxms1p6mIvcDMJYRj1DzYn7qQfwfGYpGOc_eXw,897
|
|
66
|
+
normalization/steps/text/replace_currency.py,sha256=uxUoIaqlHZ_W-spZFDti9xltyoQMqtVgg1oNxnTmkgw,1078
|
|
67
|
+
normalization/steps/word/__init__.py,sha256=is7FN2PDH_z2UY0pqf507VQfPT4aByG5pMPDvQf7HAQ,77
|
|
68
|
+
normalization/steps/word/apply_word_replacements.py,sha256=0lBl95fZv55o2GPhnGzHoSOOWmAU7tjLL-nU1FGaBUA,1049
|
|
69
|
+
gladia_normalization-0.1.0.dist-info/METADATA,sha256=4b5C5-86kGHleJ2Dlatyn7m7an0h59jH6fqviwSosW8,8502
|
|
70
|
+
gladia_normalization-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
71
|
+
gladia_normalization-0.1.0.dist-info/licenses/LICENSE,sha256=2aD21qj2zViuiny_iIHezo42ztppKYfD6_6QJZJR7dU,1062
|
|
72
|
+
gladia_normalization-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gladia
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ProtectPlaceholder(str, Enum):
|
|
5
|
+
DECIMAL_SEPARATOR = "XDECIMALX"
|
|
6
|
+
EMAIL_AT = "XATX"
|
|
7
|
+
EMAIL_DOT = "XDOTX"
|
|
8
|
+
PHONE_PLUS = "XPLUSX"
|
|
9
|
+
TIME_COLON = "§"
|
|
10
|
+
UNIT_SLASH = "†"
|
|
11
|
+
UNIT_DECIMAL = "‡"
|
|
12
|
+
NUMBER_SEPARATOR = "¤"
|
|
13
|
+
SPELLING_SUFFIX = "xltrx"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
PLACEHOLDER_FALLBACK_CHARS: dict[str, str] = {
|
|
17
|
+
ProtectPlaceholder.EMAIL_AT: "@",
|
|
18
|
+
ProtectPlaceholder.EMAIL_DOT: ".",
|
|
19
|
+
ProtectPlaceholder.PHONE_PLUS: "+",
|
|
20
|
+
ProtectPlaceholder.TIME_COLON: ":",
|
|
21
|
+
ProtectPlaceholder.UNIT_SLASH: "/",
|
|
22
|
+
ProtectPlaceholder.UNIT_DECIMAL: ".",
|
|
23
|
+
ProtectPlaceholder.DECIMAL_SEPARATOR: ".",
|
|
24
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
from typing import TypeAlias
|
|
3
|
+
|
|
4
|
+
# Semantic type aliases for LanguageConfig dict fields.
|
|
5
|
+
# All are dict[str, str] structurally, but named to convey intent and
|
|
6
|
+
# make the config contract self-documenting for new language contributors.
|
|
7
|
+
|
|
8
|
+
TimeWords: TypeAlias = dict[str, str]
|
|
9
|
+
"""Maps spoken time values to digit strings.
|
|
10
|
+
Covers clock hours (1-12) and minute-worth values (13-50).
|
|
11
|
+
Example: {'one': '1', ..., 'twelve': '12', 'thirteen': '13', ..., 'fifty': '50'}
|
|
12
|
+
|
|
13
|
+
Compound minute expressions (e.g. 'twenty-one') are language-specific behavior
|
|
14
|
+
and are NOT stored here — see LanguageOperators.get_compound_minutes().
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
SentenceReplacements: TypeAlias = dict[str, str]
|
|
18
|
+
"""Maps multi-word phrases to their normalized replacements.
|
|
19
|
+
Applied longest-match first. Example: {'good bye': 'goodbye'}
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
DigitWords: TypeAlias = dict[str, str]
|
|
23
|
+
"""Maps word forms of single digits (0-9) to their digit characters.
|
|
24
|
+
Include both canonical forms and common spoken aliases.
|
|
25
|
+
Example (English): {'zero': '0', 'oh': '0', 'o': '0', 'one': '1', ..., 'nine': '9'}
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
CurrencySymbols: TypeAlias = dict[str, str]
|
|
29
|
+
"""Maps currency symbols to their corresponding words."""
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass
|
|
33
|
+
class LanguageConfig:
|
|
34
|
+
code: str
|
|
35
|
+
"""ISO language code (e.g. 'en', 'fr') or 'default' for the language-neutral fallback."""
|
|
36
|
+
decimal_separator: str = "."
|
|
37
|
+
"""Decimal separator character."""
|
|
38
|
+
thousand_separator: str = ","
|
|
39
|
+
"""Thousands separator character."""
|
|
40
|
+
decimal_word: str | None = None
|
|
41
|
+
"""Word used for decimal separator (e.g. 'point' in English, 'virgule' in French).
|
|
42
|
+
None = decimal-word steps are skipped."""
|
|
43
|
+
symbols_to_words: dict[str, str] = field(default_factory=dict)
|
|
44
|
+
"""Maps symbols to their corresponding words. Example: {'@': 'at', '.': 'dot', '+': 'plus'}"""
|
|
45
|
+
currency_symbol_to_word: CurrencySymbols = field(default_factory=dict)
|
|
46
|
+
"""Maps currency symbols to their corresponding words. Example: {'€': 'euros', '$': 'dollars', '£': 'pounds', '¢': 'cents', '¥': 'yens'}"""
|
|
47
|
+
filler_words: list[str] = field(default_factory=list)
|
|
48
|
+
"""Words to ignore during parsing."""
|
|
49
|
+
oclock_word: str | None = None
|
|
50
|
+
"""The word or phrase meaning 'o'clock' in this language (e.g. "o'clock" for English).
|
|
51
|
+
Used by convert_oclock_to_numeric_time. None = step is skipped."""
|
|
52
|
+
time_words: TimeWords | None = None
|
|
53
|
+
"""Maps spoken time values to digit strings (hours 1-12 and minute values 13-50).
|
|
54
|
+
Used by time normalization steps (o'clock patterns and word-based time patterns).
|
|
55
|
+
Compound minute forms like 'twenty-one' are NOT included here — define them
|
|
56
|
+
in LanguageOperators.get_compound_minutes() instead.
|
|
57
|
+
None = time word steps are skipped."""
|
|
58
|
+
sentence_replacements: SentenceReplacements | None = None
|
|
59
|
+
"""Multi-word phrase replacements applied before word splitting.
|
|
60
|
+
Applied longest-match first. Used by apply_sentence_level_replacements. None = step is skipped."""
|
|
61
|
+
digit_words: DigitWords | None = None
|
|
62
|
+
"""Maps word forms of single digits (0-9) to their digit characters.
|
|
63
|
+
Used by steps that recognize isolated digit words in sequences or
|
|
64
|
+
adjacent to special tokens (e.g. 'dot' in IP addresses / versions).
|
|
65
|
+
Example (English): {'zero': '0', 'oh': '0', 'o': '0', 'one': '1', ..., 'nine': '9'}
|
|
66
|
+
None = steps requiring digit word recognition are skipped."""
|
|
67
|
+
number_words: list[str] | None = None
|
|
68
|
+
"""All number-related words for this language (digits, teens, tens, multipliers).
|
|
69
|
+
Used by steps that need to identify number words in context (e.g. punctuation normalization).
|
|
70
|
+
Example (English): ["zero", "oh", "o", "one", ..., "hundred", "thousand", "million"]
|
|
71
|
+
None = steps requiring number word recognition are skipped."""
|
|
72
|
+
plus_word: str | None = None
|
|
73
|
+
"""The word for 'plus' in this language (e.g. "plus" for English).
|
|
74
|
+
Used by protect_plus_word_before_digit_words. None = step is skipped."""
|
|
75
|
+
ordinal_suffixes: list[str] | None = None
|
|
76
|
+
"""Ordinal number suffixes for this language (e.g. ["st", "nd", "rd", "th"] for English).
|
|
77
|
+
Used by steps that need to detect ordinal numbers. None = ordinal detection is skipped."""
|
|
78
|
+
am_word: str | None = None
|
|
79
|
+
"""Canonical AM time designator (e.g. "am" for English).
|
|
80
|
+
Used by am/pm time formatting steps. None = am/pm steps are skipped."""
|
|
81
|
+
pm_word: str | None = None
|
|
82
|
+
"""Canonical PM time designator (e.g. "pm" for English).
|
|
83
|
+
Used by am/pm time formatting steps. None = am/pm steps are skipped."""
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from normalization.languages.base.language_config import LanguageConfig
|
|
2
|
+
|
|
3
|
+
_DEFAULT_CONFIG = LanguageConfig(code="default")
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class LanguageOperators:
|
|
7
|
+
"""
|
|
8
|
+
Base language operator and language-neutral fallback.
|
|
9
|
+
|
|
10
|
+
Directly instantiable: when no config is provided, uses a minimal
|
|
11
|
+
language-neutral config (code="default") with empty symbol/currency
|
|
12
|
+
mappings and all optional fields set to None.
|
|
13
|
+
|
|
14
|
+
Adding a new language = subclassing this and implementing the relevant
|
|
15
|
+
methods. Each method is intentionally fine-grained so contributors can
|
|
16
|
+
override only what they need. Default implementations are all no-ops.
|
|
17
|
+
|
|
18
|
+
Number-related *data* (digit_words, number_words) lives in LanguageConfig.
|
|
19
|
+
Override expand_written_numbers when the expansion *algorithm* differs.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(self, config: LanguageConfig | None = None):
|
|
23
|
+
self.config = config if config is not None else _DEFAULT_CONFIG
|
|
24
|
+
|
|
25
|
+
def expand_contractions(self, text: str) -> str:
|
|
26
|
+
"""Expand contractions (e.g. it's -> it is). No-op by default."""
|
|
27
|
+
return text
|
|
28
|
+
|
|
29
|
+
def normalize_numeric_time_formats(self, text: str) -> str:
|
|
30
|
+
"""Normalize numeric time formats (e.g. 05:45pm -> 5:45 pm). No-op by default."""
|
|
31
|
+
return text
|
|
32
|
+
|
|
33
|
+
def fix_one_word_in_numeric_contexts(self, text: str) -> str:
|
|
34
|
+
"""
|
|
35
|
+
Convert the language word for 'one' to its digit when adjacent to other digits.
|
|
36
|
+
|
|
37
|
+
Example (English): '10 one one' -> '10 1 1', 'one 5' -> '1 5'
|
|
38
|
+
No-op by default.
|
|
39
|
+
"""
|
|
40
|
+
return text
|
|
41
|
+
|
|
42
|
+
def get_word_replacements(self) -> dict[str, str]:
|
|
43
|
+
"""Return the word-level replacement dict for this language. Empty by default."""
|
|
44
|
+
return {}
|
|
45
|
+
|
|
46
|
+
def get_compound_minutes(self) -> dict[str, str]:
|
|
47
|
+
"""Build compound minute expressions for this language (e.g. 'twenty-one' → '21').
|
|
48
|
+
|
|
49
|
+
Called by word-based time pattern steps to match spoken compound minute values
|
|
50
|
+
such as 'two twenty-one p.m' → '2:21 pm'.
|
|
51
|
+
|
|
52
|
+
Compound minute formation is language-specific: English uses 'twenty-one' /
|
|
53
|
+
'twenty one', but other languages may form these differently (or not at all).
|
|
54
|
+
Return an empty dict if the language does not use compound minute expressions.
|
|
55
|
+
"""
|
|
56
|
+
return {}
|
|
57
|
+
|
|
58
|
+
def expand_written_numbers(self, text: str) -> str:
|
|
59
|
+
"""
|
|
60
|
+
Expand written-out number expressions to digit form.
|
|
61
|
+
|
|
62
|
+
Example: "twenty three" -> "23", "fifty" -> "50", "one hundred" -> "100"
|
|
63
|
+
Return the text unchanged if not applicable for this language.
|
|
64
|
+
"""
|
|
65
|
+
return text
|