-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add german, italian, and spanish text normalization #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
99c4ddd
feat: added italian language
egenthon-cmd ac743b2
test: added italian language tests
egenthon-cmd a6958ed
feat: add german language
egenthon-cmd 49339e4
test: added german language tests
egenthon-cmd 8318ca2
feat: added spanish language
egenthon-cmd 2692074
Merge branch 'main' into feat/add-metrics-api-languages
Karamouche a6029dc
refactor: restructure normalization tests to group by language
Karamouche 18ebc5a
refactor: test files structure for language normalization
Karamouche 6934992
test: update language normalization tests for German, French, Italian…
Karamouche f33ddb3
fix(spanish): correct decimal word from "punto" to "coma" in Spanish …
Karamouche 8568b7f
fix(german): remove incorrect replacement for "bis" in German languag…
Karamouche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ wheels/ | |
| *.egg-info | ||
| .ruff_cache/ | ||
| .pytest_cache/ | ||
| .DS_Store | ||
|
|
||
|
|
||
| # Virtual environments | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| from . import english, french | ||
| from . import english, french, german, italian, spanish | ||
| from .base import LanguageOperators | ||
| from .registry import get_language_registry, register_language | ||
|
|
||
| register_language(LanguageOperators) | ||
|
|
||
| __all__ = ["english", "french", "get_language_registry"] | ||
| __all__ = ["english", "french", "german", "italian", "spanish", "get_language_registry"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from .operators import GermanOperators | ||
| from .replacements import GERMAN_REPLACEMENTS | ||
|
|
||
| __all__ = [ | ||
| "GermanOperators", | ||
| "GERMAN_REPLACEMENTS", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| from normalization.languages.base import LanguageConfig, LanguageOperators | ||
| from normalization.languages.german.replacements import GERMAN_REPLACEMENTS | ||
| from normalization.languages.german.sentence_replacements import ( | ||
| GERMAN_SENTENCE_REPLACEMENTS, | ||
| ) | ||
| from normalization.languages.registry import register_language | ||
|
|
||
| GERMAN_CONFIG = LanguageConfig( | ||
| code="de", | ||
| decimal_separator=",", | ||
| decimal_word="komma", | ||
| thousand_separator=".", | ||
| symbols_to_words={ | ||
| "@": "at", | ||
| ".": "punkt", | ||
| "+": "plus", | ||
| "=": "gleich", | ||
| ">": "größer als", | ||
| "<": "kleiner als", | ||
| "°": "grad", | ||
| "°C": "grad celsius", | ||
| "°F": "grad fahrenheit", | ||
| "%": "prozent", | ||
| }, | ||
| currency_symbol_to_word={ | ||
| "€": "euros", | ||
| "$": "dollars", | ||
| "£": "pounds", | ||
| "¢": "cents", | ||
| "¥": "yens", | ||
| }, | ||
| filler_words=["äh", "ähm", "hm", "also", "naja", "halt"], | ||
| sentence_replacements=GERMAN_SENTENCE_REPLACEMENTS, | ||
| ) | ||
|
|
||
|
|
||
| @register_language | ||
| class GermanOperators(LanguageOperators): | ||
| def __init__(self): | ||
| super().__init__(GERMAN_CONFIG) | ||
|
|
||
| def get_word_replacements(self) -> dict[str, str]: | ||
| return GERMAN_REPLACEMENTS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| GERMAN_REPLACEMENTS: dict[str, str] = { | ||
| "u.": "unter", | ||
| "chr.": "christus", | ||
| "rissströmungen": "riss-strömungen", | ||
| "kilometer": "km", | ||
| "xdrtb": "xdr-tb", | ||
| "dualradio": "dual-radio", | ||
| "st.": "sankt", | ||
| "maubewegung": "mau-bewegung", | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| GERMAN_SENTENCE_REPLACEMENTS: dict[str, str] = { | ||
| "regimeet kritischen": "regimekritischen", | ||
| "cannabis joints": "cannabisjoints", | ||
| "kampf handlungen": "kampfhandlungen", | ||
| "erwachsenen pornografie": "erwachsenenpornographie", | ||
| "standbild format": "standbildformat", | ||
| "internet radio seite": "internetradioseite", | ||
| "alt gedienten": "altgedienten", | ||
| "6 tage krieg": "sechstagekrieg", | ||
| "kreuzungs punkt": "kreuzungspunkt", | ||
| "wild card": "wildcard", | ||
| "national parks": "nationalparks", | ||
| "internet suche": "internetsuche", | ||
| "gleichgewicht geschlechtliche": "gleichgeschlechtlichen", | ||
| "welt kulturerbegebiete": "weltkulturerbegebiete", | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from .operators import ItalianOperators | ||
| from .replacements import ITALIAN_REPLACEMENTS | ||
|
|
||
| __all__ = [ | ||
| "ItalianOperators", | ||
| "ITALIAN_REPLACEMENTS", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import re | ||
|
|
||
| from normalization.languages.base import LanguageConfig, LanguageOperators | ||
| from normalization.languages.italian.replacements import ITALIAN_REPLACEMENTS | ||
| from normalization.languages.registry import register_language | ||
|
|
||
| # Single digits 1–9: shared by digit_words and any future time/compound helpers. | ||
| _ONE_TO_NINE: dict[str, str] = { | ||
| "uno": "1", | ||
| "due": "2", | ||
| "tre": "3", | ||
| "quattro": "4", | ||
| "cinque": "5", | ||
| "sei": "6", | ||
| "sette": "7", | ||
| "otto": "8", | ||
| "nove": "9", | ||
| } | ||
|
|
||
| ITALIAN_SENTENCE_REPLACEMENTS: dict[str, str] = { | ||
| # Spoken percentages (“dieci per cento”) → one canonical form aligned with “%” → percento | ||
| "per cento": "percento", | ||
| } | ||
|
|
||
| ITALIAN_CONFIG = LanguageConfig( | ||
| code="it", | ||
| decimal_separator=",", | ||
| decimal_word="virgola", | ||
| thousand_separator=".", | ||
| symbols_to_words={ | ||
| "@": "chiocciola", | ||
| ".": "punto", | ||
| "+": "più", | ||
| "=": "uguale a", | ||
| ">": "maggiore di", | ||
| "<": "minore di", | ||
| "°": "grado", | ||
| "°C": "gradi celsius", | ||
| "°F": "gradi fahrenheit", | ||
| "%": "percento", | ||
| }, | ||
| currency_symbol_to_word={ | ||
| "€": "euro", | ||
| "$": "dollari", | ||
| "£": "sterline", | ||
| "¢": "centesimi", | ||
| "¥": "yen", | ||
| }, | ||
| filler_words=[ | ||
| "eh", | ||
| "ehm", | ||
| "mm", | ||
| "mh", | ||
| "cioè", | ||
| "cioe", | ||
| "tipo", | ||
| "insomma", | ||
| "allora", | ||
| "beh", | ||
| "bah", | ||
| "dunque", | ||
| "magari", | ||
| "praticamente", | ||
| ], | ||
| sentence_replacements=ITALIAN_SENTENCE_REPLACEMENTS, | ||
| digit_words={"zero": "0", **_ONE_TO_NINE}, | ||
| number_words=[ | ||
| "zero", | ||
| *_ONE_TO_NINE, | ||
| "dieci", | ||
| "undici", | ||
| "dodici", | ||
| "tredici", | ||
| "quattordici", | ||
| "quindici", | ||
| "sedici", | ||
| "diciassette", | ||
| "diciotto", | ||
| "diciannove", | ||
| "venti", | ||
| "trenta", | ||
| "quaranta", | ||
| "cinquanta", | ||
| "sessanta", | ||
| "settanta", | ||
| "ottanta", | ||
| "novanta", | ||
| "cento", | ||
| "mille", | ||
| "mila", | ||
| "milione", | ||
| "milioni", | ||
| "miliardo", | ||
| "miliardi", | ||
| ], | ||
| plus_word="più", | ||
| ) | ||
|
|
||
|
|
||
| @register_language | ||
| class ItalianOperators(LanguageOperators): | ||
| def __init__(self): | ||
| super().__init__(ITALIAN_CONFIG) | ||
|
|
||
| def fix_one_word_in_numeric_contexts(self, text: str) -> str: | ||
| text = re.sub(r"(\d+)\s+uno\s+uno\b", r"\1 1 1", text) | ||
| text = re.sub(r"\buno\s+uno\s+(\d)", r"1 1 \1", text) | ||
| text = re.sub(r"(\d+)\s+uno\s+(\d)", r"\1 1 \2", text) | ||
| text = re.sub(r"(\d+)\s+uno\b", r"\1 1", text) | ||
| text = re.sub(r"\b(\d+)uno\b", r"\1 1", text) | ||
| text = re.sub(r"\buno\s+(\d)", r"1 \1", text) | ||
| text = re.sub(r"^uno\s+(?=[a-z])", "1 ", text) | ||
|
Karamouche marked this conversation as resolved.
|
||
| return text | ||
|
|
||
| def get_word_replacements(self) -> dict[str, str]: | ||
| return ITALIAN_REPLACEMENTS | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| ITALIAN_REPLACEMENTS: dict[str, str] = { | ||
| "avv": "avvocato", | ||
| "dott": "dottor", | ||
| "dr": "dottor", | ||
| "ecc": "eccetera", | ||
| "etc": "eccetera", | ||
| "prof": "professore", | ||
| "tel": "telefono", | ||
| "versus": "contro", | ||
| "vs": "contro", | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from .operators import SpanishOperators | ||
| from .replacements import SPANISH_REPLACEMENTS | ||
|
|
||
| __all__ = [ | ||
| "SpanishOperators", | ||
| "SPANISH_REPLACEMENTS", | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.