text-converters 0.2.1__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.
- text_converters/__init__.py +31 -0
- text_converters/character_converters.py +318 -0
- text_converters/py.typed +0 -0
- text_converters-0.2.1.dist-info/METADATA +222 -0
- text_converters-0.2.1.dist-info/RECORD +8 -0
- text_converters-0.2.1.dist-info/WHEEL +5 -0
- text_converters-0.2.1.dist-info/licenses/LICENSE +21 -0
- text_converters-0.2.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Text Converters Package
|
|
3
|
+
|
|
4
|
+
A shared package for character conversion utilities across multiple languages.
|
|
5
|
+
Provides functions to convert characters from various languages to English equivalents.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .character_converters import (
|
|
9
|
+
CHARACTER_CONVERTERS,
|
|
10
|
+
convert_french_characters_to_english,
|
|
11
|
+
convert_german_characters_to_english,
|
|
12
|
+
convert_greek_characters_to_english,
|
|
13
|
+
convert_spanish_characters_to_english,
|
|
14
|
+
convert_swedish_characters_to_english,
|
|
15
|
+
get_character_converter,
|
|
16
|
+
no_conversion,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
__version__ = "0.2.1"
|
|
20
|
+
__author__ = "Nikos Paximadakis"
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"CHARACTER_CONVERTERS",
|
|
24
|
+
"convert_french_characters_to_english",
|
|
25
|
+
"convert_german_characters_to_english",
|
|
26
|
+
"convert_greek_characters_to_english",
|
|
27
|
+
"convert_spanish_characters_to_english",
|
|
28
|
+
"convert_swedish_characters_to_english",
|
|
29
|
+
"get_character_converter",
|
|
30
|
+
"no_conversion",
|
|
31
|
+
]
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Character conversion utilities for different languages.
|
|
3
|
+
This module provides various character conversion functions that can be used
|
|
4
|
+
across multiple projects for converting characters from various languages to English equivalents.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from collections.abc import Callable
|
|
8
|
+
|
|
9
|
+
_GREEK_TO_ENGLISH: dict[str, str] = {
|
|
10
|
+
"Α": "A",
|
|
11
|
+
"Ά": "A",
|
|
12
|
+
"Β": "B",
|
|
13
|
+
"Γ": "G",
|
|
14
|
+
"Δ": "D",
|
|
15
|
+
"Ε": "E",
|
|
16
|
+
"Έ": "E",
|
|
17
|
+
"Ζ": "Z",
|
|
18
|
+
"Η": "I",
|
|
19
|
+
"Ή": "I",
|
|
20
|
+
"Θ": "TH",
|
|
21
|
+
"Ι": "I",
|
|
22
|
+
"Ί": "I",
|
|
23
|
+
"Ϊ": "I",
|
|
24
|
+
"Κ": "K",
|
|
25
|
+
"Λ": "L",
|
|
26
|
+
"Μ": "M",
|
|
27
|
+
"Ν": "N",
|
|
28
|
+
"Ξ": "X",
|
|
29
|
+
"Ο": "O",
|
|
30
|
+
"Ό": "O",
|
|
31
|
+
"Π": "P",
|
|
32
|
+
"Ρ": "R",
|
|
33
|
+
"Σ": "S",
|
|
34
|
+
"Τ": "T",
|
|
35
|
+
"Υ": "Y",
|
|
36
|
+
"Ύ": "Y",
|
|
37
|
+
"Ϋ": "Y",
|
|
38
|
+
"Φ": "F",
|
|
39
|
+
"Χ": "CH",
|
|
40
|
+
"Ψ": "PS",
|
|
41
|
+
"Ω": "O",
|
|
42
|
+
"Ώ": "O",
|
|
43
|
+
"α": "a",
|
|
44
|
+
"ά": "a",
|
|
45
|
+
"β": "b",
|
|
46
|
+
"γ": "g",
|
|
47
|
+
"δ": "d",
|
|
48
|
+
"ε": "e",
|
|
49
|
+
"έ": "e",
|
|
50
|
+
"ζ": "z",
|
|
51
|
+
"η": "i",
|
|
52
|
+
"ή": "i",
|
|
53
|
+
"θ": "th",
|
|
54
|
+
"ι": "i",
|
|
55
|
+
"ί": "i",
|
|
56
|
+
"ϊ": "i",
|
|
57
|
+
"ΐ": "i",
|
|
58
|
+
"κ": "k",
|
|
59
|
+
"λ": "l",
|
|
60
|
+
"μ": "m",
|
|
61
|
+
"ν": "n",
|
|
62
|
+
"ξ": "x",
|
|
63
|
+
"ο": "o",
|
|
64
|
+
"ό": "o",
|
|
65
|
+
"π": "p",
|
|
66
|
+
"ρ": "r",
|
|
67
|
+
"σ": "s",
|
|
68
|
+
"ς": "s",
|
|
69
|
+
"τ": "t",
|
|
70
|
+
"υ": "y",
|
|
71
|
+
"ύ": "y",
|
|
72
|
+
"ϋ": "y",
|
|
73
|
+
"ΰ": "y",
|
|
74
|
+
"φ": "f",
|
|
75
|
+
"χ": "ch",
|
|
76
|
+
"ψ": "ps",
|
|
77
|
+
"ω": "o",
|
|
78
|
+
"ώ": "o",
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# Capital letters whose Latin form has two letters. "TH" is right inside an
|
|
82
|
+
# all-capitals word (ΑΘΗΝΑ -> ATHINA) but wrong at the start of a normal one
|
|
83
|
+
# (Θεσσαλονίκη -> Thessaloniki), so the case of the second letter depends on the
|
|
84
|
+
# neighbours.
|
|
85
|
+
_GREEK_CAPITAL_DIGRAPHS: dict[str, str] = {"Θ": "TH", "Χ": "CH", "Ψ": "PS"}
|
|
86
|
+
# The pair ου is written "ou" (Παπαδόπουλος -> Papadopoulos), not "oy".
|
|
87
|
+
_GREEK_OMICRON: frozenset[str] = frozenset("οόΟΌ")
|
|
88
|
+
_GREEK_UPSILON: dict[str, str] = {"υ": "u", "ύ": "u", "Υ": "U", "Ύ": "U"}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def convert_greek_characters_to_english(text: str) -> str:
|
|
92
|
+
"""
|
|
93
|
+
Transliterate Greek letters (with or without tonos) to Latin letters.
|
|
94
|
+
|
|
95
|
+
Letter by letter, close to the Greek standard ELOT 743 for single letters:
|
|
96
|
+
η is "i" (Θεσσαλονίκη -> Thessaloniki), ου is "ou" (Παπαδόπουλος ->
|
|
97
|
+
Papadopoulos), and Θ, Χ, Ψ give "Th", "Ch", "Ps" unless they stand in an
|
|
98
|
+
all-capitals word (ΑΘΗΝΑ -> ATHINA). The other letter pairs ELOT treats
|
|
99
|
+
specially (αυ, ευ, μπ, γγ, ...) are not handled.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
text: Text containing Greek characters
|
|
103
|
+
|
|
104
|
+
Returns:
|
|
105
|
+
Text with Greek characters converted to Latin letters
|
|
106
|
+
"""
|
|
107
|
+
result: list[str] = []
|
|
108
|
+
for index, char in enumerate(text):
|
|
109
|
+
preceding = text[index - 1] if index > 0 else ""
|
|
110
|
+
if char in _GREEK_UPSILON and preceding in _GREEK_OMICRON:
|
|
111
|
+
result.append(_GREEK_UPSILON[char])
|
|
112
|
+
continue
|
|
113
|
+
digraph = _GREEK_CAPITAL_DIGRAPHS.get(char)
|
|
114
|
+
if digraph is None:
|
|
115
|
+
result.append(_GREEK_TO_ENGLISH.get(char, char))
|
|
116
|
+
continue
|
|
117
|
+
following = text[index + 1] if index + 1 < len(text) else ""
|
|
118
|
+
in_capitals_word = following.isupper() or (
|
|
119
|
+
not following.isalpha() and preceding.isupper()
|
|
120
|
+
)
|
|
121
|
+
result.append(digraph if in_capitals_word else digraph.capitalize())
|
|
122
|
+
return "".join(result)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def convert_swedish_characters_to_english(text: str) -> str:
|
|
126
|
+
"""
|
|
127
|
+
Convert Swedish characters to English equivalents.
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
text: Text containing Swedish characters
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
Text with Swedish characters converted to English equivalents
|
|
134
|
+
"""
|
|
135
|
+
swedish_to_english_mapping: dict[str, str] = {
|
|
136
|
+
"Å": "A",
|
|
137
|
+
"å": "a",
|
|
138
|
+
"Ä": "A",
|
|
139
|
+
"ä": "a",
|
|
140
|
+
"Ö": "O",
|
|
141
|
+
"ö": "o",
|
|
142
|
+
"É": "E",
|
|
143
|
+
"é": "e",
|
|
144
|
+
"È": "E",
|
|
145
|
+
"è": "e",
|
|
146
|
+
"Ü": "U",
|
|
147
|
+
"ü": "u",
|
|
148
|
+
"Ñ": "N",
|
|
149
|
+
"ñ": "n",
|
|
150
|
+
"Ç": "C",
|
|
151
|
+
"ç": "c",
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return "".join(swedish_to_english_mapping.get(char, char) for char in text)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def convert_german_characters_to_english(text: str) -> str:
|
|
158
|
+
"""
|
|
159
|
+
Convert German characters to English equivalents.
|
|
160
|
+
|
|
161
|
+
Args:
|
|
162
|
+
text: Text containing German characters
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
Text with German characters converted to English equivalents
|
|
166
|
+
"""
|
|
167
|
+
german_to_english_mapping: dict[str, str] = {
|
|
168
|
+
"Ä": "Ae",
|
|
169
|
+
"ä": "ae",
|
|
170
|
+
"Ö": "Oe",
|
|
171
|
+
"ö": "oe",
|
|
172
|
+
"Ü": "Ue",
|
|
173
|
+
"ü": "ue",
|
|
174
|
+
"ß": "ss",
|
|
175
|
+
"É": "E",
|
|
176
|
+
"é": "e",
|
|
177
|
+
"È": "E",
|
|
178
|
+
"è": "e",
|
|
179
|
+
"À": "A",
|
|
180
|
+
"à": "a",
|
|
181
|
+
"Ò": "O",
|
|
182
|
+
"ò": "o",
|
|
183
|
+
"Ù": "U",
|
|
184
|
+
"ù": "u",
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return "".join(german_to_english_mapping.get(char, char) for char in text)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def convert_french_characters_to_english(text: str) -> str:
|
|
191
|
+
"""
|
|
192
|
+
Convert French characters to English equivalents.
|
|
193
|
+
|
|
194
|
+
Args:
|
|
195
|
+
text: Text containing French characters
|
|
196
|
+
|
|
197
|
+
Returns:
|
|
198
|
+
Text with French characters converted to English equivalents
|
|
199
|
+
"""
|
|
200
|
+
french_to_english_mapping: dict[str, str] = {
|
|
201
|
+
"Æ": "Ae",
|
|
202
|
+
"æ": "ae",
|
|
203
|
+
"Œ": "Oe",
|
|
204
|
+
"œ": "oe",
|
|
205
|
+
"À": "A",
|
|
206
|
+
"à": "a",
|
|
207
|
+
"Á": "A",
|
|
208
|
+
"á": "a",
|
|
209
|
+
"Â": "A",
|
|
210
|
+
"â": "a",
|
|
211
|
+
"Ä": "A",
|
|
212
|
+
"ä": "a",
|
|
213
|
+
"Ç": "C",
|
|
214
|
+
"ç": "c",
|
|
215
|
+
"É": "E",
|
|
216
|
+
"é": "e",
|
|
217
|
+
"È": "E",
|
|
218
|
+
"è": "e",
|
|
219
|
+
"Ê": "E",
|
|
220
|
+
"ê": "e",
|
|
221
|
+
"Ë": "E",
|
|
222
|
+
"ë": "e",
|
|
223
|
+
"Î": "I",
|
|
224
|
+
"î": "i",
|
|
225
|
+
"Ï": "I",
|
|
226
|
+
"ï": "i",
|
|
227
|
+
"Ô": "O",
|
|
228
|
+
"ô": "o",
|
|
229
|
+
"Ö": "O",
|
|
230
|
+
"ö": "o",
|
|
231
|
+
"Ù": "U",
|
|
232
|
+
"ù": "u",
|
|
233
|
+
"Ú": "U",
|
|
234
|
+
"ú": "u",
|
|
235
|
+
"Û": "U",
|
|
236
|
+
"û": "u",
|
|
237
|
+
"Ü": "U",
|
|
238
|
+
"ü": "u",
|
|
239
|
+
"Ÿ": "Y",
|
|
240
|
+
"ÿ": "y",
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return "".join(french_to_english_mapping.get(char, char) for char in text)
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def convert_spanish_characters_to_english(text: str) -> str:
|
|
247
|
+
"""
|
|
248
|
+
Convert Spanish characters to English equivalents.
|
|
249
|
+
|
|
250
|
+
Args:
|
|
251
|
+
text: Text containing Spanish characters
|
|
252
|
+
|
|
253
|
+
Returns:
|
|
254
|
+
Text with Spanish characters converted to English equivalents
|
|
255
|
+
"""
|
|
256
|
+
spanish_to_english_mapping: dict[str, str] = {
|
|
257
|
+
"Á": "A",
|
|
258
|
+
"á": "a",
|
|
259
|
+
"É": "E",
|
|
260
|
+
"é": "e",
|
|
261
|
+
"Í": "I",
|
|
262
|
+
"í": "i",
|
|
263
|
+
"Ó": "O",
|
|
264
|
+
"ó": "o",
|
|
265
|
+
"Ú": "U",
|
|
266
|
+
"ú": "u",
|
|
267
|
+
"Ñ": "N",
|
|
268
|
+
"ñ": "n",
|
|
269
|
+
"Ü": "U",
|
|
270
|
+
"ü": "u",
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return "".join(spanish_to_english_mapping.get(char, char) for char in text)
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def no_conversion(text: str) -> str:
|
|
277
|
+
"""
|
|
278
|
+
No-op character conversion function.
|
|
279
|
+
Returns the text unchanged.
|
|
280
|
+
|
|
281
|
+
Args:
|
|
282
|
+
text: Input text
|
|
283
|
+
|
|
284
|
+
Returns:
|
|
285
|
+
Text unchanged
|
|
286
|
+
"""
|
|
287
|
+
return text
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
# Convenience dictionary for easy access
|
|
291
|
+
CHARACTER_CONVERTERS = {
|
|
292
|
+
"greek": convert_greek_characters_to_english,
|
|
293
|
+
"swedish": convert_swedish_characters_to_english,
|
|
294
|
+
"german": convert_german_characters_to_english,
|
|
295
|
+
"french": convert_french_characters_to_english,
|
|
296
|
+
"spanish": convert_spanish_characters_to_english,
|
|
297
|
+
"none": no_conversion,
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def get_character_converter(language: str = "none") -> Callable[[str], str]:
|
|
302
|
+
"""
|
|
303
|
+
Get a character converter function by language name.
|
|
304
|
+
|
|
305
|
+
Args:
|
|
306
|
+
language: Language name ('greek', 'swedish', 'german', 'french', 'spanish', 'none')
|
|
307
|
+
|
|
308
|
+
Returns:
|
|
309
|
+
Character converter function
|
|
310
|
+
|
|
311
|
+
Raises:
|
|
312
|
+
ValueError: If language is not supported
|
|
313
|
+
"""
|
|
314
|
+
if language not in CHARACTER_CONVERTERS:
|
|
315
|
+
available = ", ".join(CHARACTER_CONVERTERS.keys())
|
|
316
|
+
raise ValueError(f"Unsupported language '{language}'. Available: {available}")
|
|
317
|
+
|
|
318
|
+
return CHARACTER_CONVERTERS[language]
|
text_converters/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: text_converters
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Convert Greek, Swedish, German, French and Spanish letters to plain Latin equivalents
|
|
5
|
+
Author: Nikos Paximadakis
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Nikolaos-Paximadakis/text-converters
|
|
8
|
+
Project-URL: Repository, https://github.com/Nikolaos-Paximadakis/text-converters
|
|
9
|
+
Project-URL: Issues, https://github.com/Nikolaos-Paximadakis/text-converters/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/Nikolaos-Paximadakis/text-converters/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: transliteration,greek,elot-743,diacritics,ascii,unicode
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
22
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.11
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
31
|
+
Requires-Dist: ruff; extra == "dev"
|
|
32
|
+
Requires-Dist: mypy; extra == "dev"
|
|
33
|
+
Requires-Dist: pyright==1.1.414; extra == "dev"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# Text Converters
|
|
37
|
+
|
|
38
|
+
[](https://opensource.org/licenses/MIT)
|
|
39
|
+
[](https://www.python.org/downloads/)
|
|
40
|
+
[](https://github.com/Nikolaos-Paximadakis/text-converters)
|
|
41
|
+
|
|
42
|
+
Small, dependency-free Python functions that replace Greek letters and accented
|
|
43
|
+
Swedish, German, French and Spanish letters with plain Latin (mostly ASCII)
|
|
44
|
+
equivalents, using one fixed character map per language.
|
|
45
|
+
|
|
46
|
+
## Scope and limitations
|
|
47
|
+
|
|
48
|
+
Released under the MIT License and provided "as is", without warranty of any kind.
|
|
49
|
+
Each converter is a simple character-by-character lookup. Known limits:
|
|
50
|
+
|
|
51
|
+
- **Greek** is close to ELOT 743 for single letters, but it is not a full
|
|
52
|
+
implementation of ELOT 743 or ISO 843. `η` → `i` (`Θεσσαλονίκη` → `Thessaloniki`),
|
|
53
|
+
`ου` → `ou` (`Παπαδόπουλος` → `Papadopoulos`), and `Θ`, `Χ`, `Ψ` give `Th`, `Ch`,
|
|
54
|
+
`Ps`, or `TH`, `CH`, `PS` inside an all-capitals word (`ΑΘΗΝΑ` → `ATHINA`).
|
|
55
|
+
- Other Greek letter pairs that ELOT 743 treats specially (`αυ`, `ευ`, `μπ`, `ντ`,
|
|
56
|
+
`γγ`, ...) are converted letter by letter (`Ευρώ` → `Eyro`, `Μπαμπάς` → `Mpampas`).
|
|
57
|
+
- **German** writes umlauts as `ae`/`oe`/`ue` and `ß` as `ss`. The other converters
|
|
58
|
+
simply drop the accent (Swedish `ä` → `a`).
|
|
59
|
+
- **French** writes the ligatures `œ` and `æ` as `oe` and `ae`; like the German
|
|
60
|
+
umlauts, their capitals become `Oe` and `Ae` even in an all-capitals word.
|
|
61
|
+
- Characters missing from a language's map are returned unchanged, so the output is
|
|
62
|
+
not guaranteed to be ASCII (for example `¿`, `€` or Cyrillic letters).
|
|
63
|
+
- Conversion is one-way and loses information.
|
|
64
|
+
|
|
65
|
+
## Installation
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install text-converters
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Or the latest development version from GitHub:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install git+https://github.com/Nikolaos-Paximadakis/text-converters.git
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
For development:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
git clone https://github.com/Nikolaos-Paximadakis/text-converters.git
|
|
81
|
+
cd text-converters
|
|
82
|
+
pip install -e ".[dev]"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Usage
|
|
86
|
+
|
|
87
|
+
### Basic Usage
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from text_converters import convert_greek_characters_to_english
|
|
91
|
+
|
|
92
|
+
# Convert Greek text to English
|
|
93
|
+
greek_text = "Αθήνα"
|
|
94
|
+
english_text = convert_greek_characters_to_english(greek_text)
|
|
95
|
+
print(english_text) # Output: "Athina"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Using the Character Converter Dictionary
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from text_converters import CHARACTER_CONVERTERS
|
|
102
|
+
|
|
103
|
+
# Get a specific converter
|
|
104
|
+
greek_converter = CHARACTER_CONVERTERS["greek"]
|
|
105
|
+
result = greek_converter("Γεια σας") # "Geia sas"
|
|
106
|
+
|
|
107
|
+
# Available converters
|
|
108
|
+
print(CHARACTER_CONVERTERS.keys())
|
|
109
|
+
# dict_keys(['greek', 'swedish', 'german', 'french', 'spanish', 'none'])
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Using the Getter Function
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from text_converters import get_character_converter
|
|
116
|
+
|
|
117
|
+
# Get a converter by language name
|
|
118
|
+
converter = get_character_converter("greek")
|
|
119
|
+
result = converter("Καλησπέρα") # "Kalispera"
|
|
120
|
+
|
|
121
|
+
# Handle unsupported languages
|
|
122
|
+
try:
|
|
123
|
+
converter = get_character_converter("unsupported")
|
|
124
|
+
except ValueError as e:
|
|
125
|
+
print(e) # "Unsupported language 'unsupported'. Available: greek, swedish, german, french, spanish, none"
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Multiple Language Support
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from text_converters import (
|
|
132
|
+
convert_greek_characters_to_english,
|
|
133
|
+
convert_german_characters_to_english,
|
|
134
|
+
convert_french_characters_to_english,
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
# Greek
|
|
138
|
+
greek_result = convert_greek_characters_to_english("Γεια σας") # "Geia sas"
|
|
139
|
+
|
|
140
|
+
# German
|
|
141
|
+
german_result = convert_german_characters_to_english("Grüße") # "Gruesse"
|
|
142
|
+
|
|
143
|
+
# French
|
|
144
|
+
french_result = convert_french_characters_to_english("Bonjour") # "Bonjour"
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Supported Languages
|
|
148
|
+
|
|
149
|
+
| Language | Function | Example |
|
|
150
|
+
|----------|----------|---------|
|
|
151
|
+
| Greek | `convert_greek_characters_to_english` | "Αθήνα" → "Athina" |
|
|
152
|
+
| Swedish | `convert_swedish_characters_to_english` | "Göteborg" → "Goteborg" |
|
|
153
|
+
| German | `convert_german_characters_to_english` | "Grüße" → "Gruesse" |
|
|
154
|
+
| French | `convert_french_characters_to_english` | "Café" → "Cafe" |
|
|
155
|
+
| Spanish | `convert_spanish_characters_to_english` | "España" → "Espana" |
|
|
156
|
+
| None | `no_conversion` | "Hello" → "Hello" |
|
|
157
|
+
|
|
158
|
+
## API Reference
|
|
159
|
+
|
|
160
|
+
### Functions
|
|
161
|
+
|
|
162
|
+
#### `convert_greek_characters_to_english(text: str) -> str`
|
|
163
|
+
Convert Greek characters to English equivalents.
|
|
164
|
+
|
|
165
|
+
**Parameters:**
|
|
166
|
+
- `text` (str): Text containing Greek characters
|
|
167
|
+
|
|
168
|
+
**Returns:**
|
|
169
|
+
- `str`: Text with Greek characters converted to English equivalents
|
|
170
|
+
|
|
171
|
+
#### `get_character_converter(language: str = "none")`
|
|
172
|
+
Get a character converter function by language name.
|
|
173
|
+
|
|
174
|
+
**Parameters:**
|
|
175
|
+
- `language` (str): Language name ('greek', 'swedish', 'german', 'french', 'spanish', 'none')
|
|
176
|
+
|
|
177
|
+
**Returns:**
|
|
178
|
+
- Function: Character converter function
|
|
179
|
+
|
|
180
|
+
**Raises:**
|
|
181
|
+
- `ValueError`: If language is not supported
|
|
182
|
+
|
|
183
|
+
### Constants
|
|
184
|
+
|
|
185
|
+
#### `CHARACTER_CONVERTERS`
|
|
186
|
+
Dictionary mapping language names to their respective converter functions.
|
|
187
|
+
|
|
188
|
+
## Development
|
|
189
|
+
|
|
190
|
+
### Running Tests
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
pip install -e ".[dev]"
|
|
194
|
+
pytest
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Lint, Format and Type Checks
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
ruff check .
|
|
201
|
+
ruff format --check .
|
|
202
|
+
mypy
|
|
203
|
+
pyright
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
|
|
208
|
+
MIT License. See [LICENSE](https://github.com/Nikolaos-Paximadakis/text-converters/blob/main/LICENSE).
|
|
209
|
+
|
|
210
|
+
## Contributing
|
|
211
|
+
|
|
212
|
+
When adding new language converters:
|
|
213
|
+
|
|
214
|
+
1. Add the conversion function following the existing pattern
|
|
215
|
+
2. Add the function to the `CHARACTER_CONVERTERS` dictionary
|
|
216
|
+
3. Update the `__all__` list in `__init__.py`
|
|
217
|
+
4. Add tests for the new converter
|
|
218
|
+
5. Update this README with examples
|
|
219
|
+
|
|
220
|
+
## Changes
|
|
221
|
+
|
|
222
|
+
See the [changelog](https://github.com/Nikolaos-Paximadakis/text-converters/blob/main/CHANGELOG.md).
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
text_converters/__init__.py,sha256=IW0x7t3-C-vP4IgiipIKsgcEsUmIxQITi8DDzSjRlJc,927
|
|
2
|
+
text_converters/character_converters.py,sha256=zJDLmouFgMWYki04AqvwFBfncDbOEt4wOshYNG4Nd-k,8136
|
|
3
|
+
text_converters/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
text_converters-0.2.1.dist-info/licenses/LICENSE,sha256=J7-5_UggpqevDxCt3m1r6Xt7oZnv1C46cXgY7SM9Dc0,1100
|
|
5
|
+
text_converters-0.2.1.dist-info/METADATA,sha256=hCK8yIivQD6DHgTbJDHdiOnhxnjy4fnY-7MhoPuPCHE,7303
|
|
6
|
+
text_converters-0.2.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
7
|
+
text_converters-0.2.1.dist-info/top_level.txt,sha256=qKI6KHMgyM8AVdvIQxCc6fC_mVaK6a__bu8skc3oYsI,16
|
|
8
|
+
text_converters-0.2.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Nikos Paximadakis
|
|
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 @@
|
|
|
1
|
+
text_converters
|