worldalphabets 0.0.6__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 will wade
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,341 @@
1
+ Metadata-Version: 2.4
2
+ Name: worldalphabets
3
+ Version: 0.0.6
4
+ Requires-Python: >=3.11
5
+ Description-Content-Type: text/markdown
6
+ License-File: LICENSE
7
+ Requires-Dist: langcodes>=3.3.0
8
+ Requires-Dist: language-data>=1.1.0
9
+ Provides-Extra: dev
10
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
11
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
12
+ Requires-Dist: build>=0.10.0; extra == "dev"
13
+ Dynamic: license-file
14
+
15
+ # WorldAlphabets
16
+
17
+ A tool to access alphabets of the world with Python and Node interfaces.
18
+
19
+ ## Usage
20
+
21
+ ### Python
22
+
23
+ To load the data in Python:
24
+
25
+ ```python
26
+ from worldalphabets import load_alphabet
27
+
28
+ alphabet = load_alphabet("en")
29
+ print(alphabet.uppercase[:5]) # ['A', 'B', 'C', 'D', 'E']
30
+ print(alphabet.frequency['e'])
31
+ ```
32
+
33
+ ### Node.js
34
+
35
+ #### From npm
36
+
37
+ Install the package from npm:
38
+
39
+ ```bash
40
+ npm install worldalphabets
41
+ ```
42
+
43
+ Then, you can use the functions in your project:
44
+
45
+ ```javascript
46
+ const { getUppercase, getLowercase, getFrequency, getAvailableCodes } = require('worldalphabets');
47
+
48
+ async function main() {
49
+ const codes = await getAvailableCodes();
50
+ console.log('Available codes (first 5):', codes.slice(0, 5));
51
+
52
+ const uppercaseEn = await getUppercase('en');
53
+ console.log('English uppercase:', uppercaseEn);
54
+
55
+ const lowercaseFr = await getLowercase('fr');
56
+ console.log('French lowercase:', lowercaseFr);
57
+
58
+ const frequencyDe = await getFrequency('de');
59
+ console.log('German frequency for "a":', frequencyDe['a']);
60
+ }
61
+
62
+ main();
63
+ ```
64
+
65
+ #### Local Usage
66
+
67
+ If you have cloned the repository, you can use the module directly:
68
+
69
+ ```javascript
70
+ const { getUppercase } = require('./index');
71
+
72
+ async function main() {
73
+ const uppercaseEn = await getUppercase('en');
74
+ console.log('English uppercase:', uppercaseEn);
75
+ }
76
+
77
+ main();
78
+ ```
79
+
80
+ ## Supported Languages
81
+
82
+ Alphabet JSON files are available for these ISO language codes
83
+ (language names from [langcodes](https://pypi.org/project/langcodes/)):
84
+
85
+ | Code | Language |
86
+ |------|----------|
87
+ | af | Afrikaans |
88
+ | ak | Akan |
89
+ | am | Amharic |
90
+ | ar | Arabic |
91
+ | ast | Asturian |
92
+ | az | Azerbaijani |
93
+ | ba | Bashkir |
94
+ | ban | Balinese |
95
+ | bax | Bamun |
96
+ | be | Belarusian |
97
+ | bg | Bulgarian |
98
+ | bku | Buhid |
99
+ | bm | Bambara |
100
+ | bn | Bangla |
101
+ | bo | Tibetan |
102
+ | bug | Buginese |
103
+ | bya | Batak |
104
+ | ca | Catalan |
105
+ | ceb | Cebuano |
106
+ | chr | Cherokee |
107
+ | ckb | Central Kurdish |
108
+ | cop | Coptic |
109
+ | cs | Czech |
110
+ | cv | Chuvash |
111
+ | da | Danish |
112
+ | de | German |
113
+ | dz | Dzongkha |
114
+ | el | Greek |
115
+ | en | English |
116
+ | eo | Esperanto |
117
+ | es | Spanish |
118
+ | et | Estonian |
119
+ | eu | Basque |
120
+ | fa | Persian |
121
+ | fi | Finnish |
122
+ | fo | Faroese |
123
+ | fr | French |
124
+ | fur | Friulian |
125
+ | ga | Irish |
126
+ | gd | Scottish Gaelic |
127
+ | gez | Geez |
128
+ | gl | Galician |
129
+ | gu | Gujarati |
130
+ | gv | Manx |
131
+ | haw | Hawaiian |
132
+ | he | Hebrew |
133
+ | hi | Hindi |
134
+ | hnn | Hanunoo |
135
+ | ht | Haitian Creole |
136
+ | hu | Hungarian |
137
+ | hy | Armenian |
138
+ | ie | Interlingue |
139
+ | is | Icelandic |
140
+ | it | Italian |
141
+ | ja | Japanese |
142
+ | jv | Javanese |
143
+ | ka | Georgian |
144
+ | kab | Kabyle |
145
+ | kk | Kazakh |
146
+ | kl | Kalaallisut |
147
+ | km | Khmer |
148
+ | kn | Kannada |
149
+ | ko | Korean |
150
+ | ks | Kashmiri |
151
+ | ksh | Colognian |
152
+ | ku | Kurdish |
153
+ | ky | Kyrgyz |
154
+ | la | Latin |
155
+ | lb | Luxembourgish |
156
+ | lep | Lepcha |
157
+ | lif | Limbu |
158
+ | lij | Ligurian |
159
+ | lis | Lisu |
160
+ | lo | Lao |
161
+ | lt | Lithuanian |
162
+ | lv | Latvian |
163
+ | mg | Malagasy |
164
+ | mid | Mandaic |
165
+ | mk | Macedonian |
166
+ | ml | Malayalam |
167
+ | mn | Mongolian |
168
+ | mo | Romanian |
169
+ | my | Burmese |
170
+ | mzn | Mazanderani |
171
+ | nds | Low German |
172
+ | ne | Nepali |
173
+ | nn | Norwegian Nynorsk |
174
+ | no | Norwegian |
175
+ | nqo | N’Ko |
176
+ | nso | Northern Sotho |
177
+ | oc | Occitan |
178
+ | or | Odia |
179
+ | pl | Polish |
180
+ | ps | Pashto |
181
+ | pt | Portuguese |
182
+ | rej | Rejang |
183
+ | rm | Romansh |
184
+ | ro | Romanian |
185
+ | ru | Russian |
186
+ | sa | Sanskrit |
187
+ | sam | Samaritan Aramaic |
188
+ | saz | Saurashtra |
189
+ | sc | Sardinian |
190
+ | se | Northern Sami |
191
+ | sg | Sango |
192
+ | si | Sinhala |
193
+ | sl | Slovenian |
194
+ | sn | Shona |
195
+ | so | Somali |
196
+ | sr | Serbian |
197
+ | su | Sundanese |
198
+ | sv | Swedish |
199
+ | syr | Syriac |
200
+ | szl | Silesian |
201
+ | ta | Tamil |
202
+ | tbw | Tagbanwa |
203
+ | te | Telugu |
204
+ | tg | Tajik |
205
+ | th | Thai |
206
+ | ti | Tigrinya |
207
+ | tk | Turkmen |
208
+ | tl | Filipino |
209
+ | tn | Tswana |
210
+ | tr | Turkish |
211
+ | tt | Tatar |
212
+ | uk | Ukrainian |
213
+ | ur | Urdu |
214
+ | vai | Vai |
215
+ | vec | Venetian |
216
+ | wo | Wolof |
217
+ | zh | Chinese |
218
+ | zh-classical | Classical Chinese |
219
+ | zh-min-nan | Min Nan Chinese |
220
+ | zh-yue | Cantonese |
221
+ | zra | Kara (Korea) |
222
+
223
+ ## Developer Guide
224
+
225
+ This project uses the
226
+ [kalenchukov/Alphabet](https://github.com/kalenchukov/Alphabet) Java repository as
227
+ the source for alphabet data. A helper script clones the repository, scans all
228
+ `*Alphabet.java` files, downloads a sample Wikipedia article for supported
229
+ languages, and writes JSON files containing the alphabet and estimated letter
230
+ frequencies. A second utility can replace those estimates with corpus
231
+ frequencies from the [Simia unigrams dataset](http://simia.net/letters/).
232
+
233
+ Each JSON file includes:
234
+
235
+ - `alphabetical` – letters of the alphabet (uppercase when the script has
236
+ case)
237
+ - `uppercase` – uppercase letters
238
+ - `lowercase` – lowercase letters
239
+ - `frequency` – relative frequency of each lowercase letter (zero when no
240
+ sample text is available)
241
+
242
+ Example JSON snippet:
243
+
244
+ ```json
245
+ {
246
+ "alphabetical": ["A", "B", ...],
247
+ "uppercase": ["A", "B", ...],
248
+ "lowercase": ["a", "b", ...],
249
+ "frequency": {"a": 0.084, "b": 0.0208, ...}
250
+ }
251
+ ```
252
+
253
+ ### Setup
254
+
255
+ This project uses `uv` for dependency management. To set up the development
256
+ environment:
257
+
258
+ ```bash
259
+ # Install uv
260
+ pipx install uv
261
+
262
+ # Create and activate a virtual environment
263
+ uv venv
264
+ source .venv/bin/activate
265
+
266
+ # Install dependencies
267
+ uv pip install -e '.[dev]'
268
+ ```
269
+
270
+ ### Data Generation
271
+
272
+ **Extract alphabets**
273
+
274
+ ```bash
275
+ uv run scripts/extract_alphabets.py
276
+ ```
277
+
278
+ The script clones the Java project and stores JSON files for every available
279
+ alphabet under `data/alphabets/`, named by ISO language code. If no sample text
280
+ is available, frequency values default to zero and the language is recorded in
281
+ `data/todo_languages.csv` for follow-up.
282
+
283
+ **Update letter frequencies**
284
+
285
+ ```bash
286
+ uv run scripts/update_frequencies.py
287
+ ```
288
+
289
+ This script downloads the `unigrams.zip` archive and rewrites each alphabet's
290
+ frequency mapping using the published counts.
291
+
292
+ **Generate alphabets from locale data**
293
+
294
+ Derive an alphabet from an ICU locale's exemplar character set:
295
+
296
+ ```bash
297
+ uv run scripts/generate_alphabet_from_locale.py <code> --locale <locale>
298
+ ```
299
+
300
+ The script writes `data/alphabets/<code>.json`, using the locale's standard
301
+ exemplar set for the base letters and populating frequency values from the
302
+ Simia unigrams dataset when available. Locales without exemplar data are
303
+ skipped.
304
+
305
+ **Generate alphabets from unigrams**
306
+
307
+ For languages present in the Simia dataset but missing here:
308
+
309
+ ```bash
310
+ uv run scripts/generate_alphabet_from_unigrams.py <code> --locale <locale> \
311
+ --block <Unicode block>
312
+ ```
313
+
314
+ The script writes `data/alphabets/<code>.json`. To list missing codes:
315
+
316
+ ```bash
317
+ uv run scripts/missing_unigram_languages.py
318
+ ```
319
+
320
+ **Generate missing alphabets**
321
+
322
+ Create alphabet files for every language in the Simia unigrams dataset that
323
+ does not yet have one:
324
+
325
+ ```bash
326
+ uv run scripts/generate_missing_alphabets.py --limit 10
327
+ ```
328
+
329
+ Omit `--limit` to process all missing languages. Each file is written under
330
+ `data/alphabets/` and combines ICU exemplar characters with Simia frequencies.
331
+
332
+ ### Linting and type checking
333
+
334
+ ```bash
335
+ ruff check .
336
+ mypy .
337
+ ```
338
+
339
+ ## Future work
340
+
341
+ - Add sample text or unigram support for more languages.
@@ -0,0 +1,327 @@
1
+ # WorldAlphabets
2
+
3
+ A tool to access alphabets of the world with Python and Node interfaces.
4
+
5
+ ## Usage
6
+
7
+ ### Python
8
+
9
+ To load the data in Python:
10
+
11
+ ```python
12
+ from worldalphabets import load_alphabet
13
+
14
+ alphabet = load_alphabet("en")
15
+ print(alphabet.uppercase[:5]) # ['A', 'B', 'C', 'D', 'E']
16
+ print(alphabet.frequency['e'])
17
+ ```
18
+
19
+ ### Node.js
20
+
21
+ #### From npm
22
+
23
+ Install the package from npm:
24
+
25
+ ```bash
26
+ npm install worldalphabets
27
+ ```
28
+
29
+ Then, you can use the functions in your project:
30
+
31
+ ```javascript
32
+ const { getUppercase, getLowercase, getFrequency, getAvailableCodes } = require('worldalphabets');
33
+
34
+ async function main() {
35
+ const codes = await getAvailableCodes();
36
+ console.log('Available codes (first 5):', codes.slice(0, 5));
37
+
38
+ const uppercaseEn = await getUppercase('en');
39
+ console.log('English uppercase:', uppercaseEn);
40
+
41
+ const lowercaseFr = await getLowercase('fr');
42
+ console.log('French lowercase:', lowercaseFr);
43
+
44
+ const frequencyDe = await getFrequency('de');
45
+ console.log('German frequency for "a":', frequencyDe['a']);
46
+ }
47
+
48
+ main();
49
+ ```
50
+
51
+ #### Local Usage
52
+
53
+ If you have cloned the repository, you can use the module directly:
54
+
55
+ ```javascript
56
+ const { getUppercase } = require('./index');
57
+
58
+ async function main() {
59
+ const uppercaseEn = await getUppercase('en');
60
+ console.log('English uppercase:', uppercaseEn);
61
+ }
62
+
63
+ main();
64
+ ```
65
+
66
+ ## Supported Languages
67
+
68
+ Alphabet JSON files are available for these ISO language codes
69
+ (language names from [langcodes](https://pypi.org/project/langcodes/)):
70
+
71
+ | Code | Language |
72
+ |------|----------|
73
+ | af | Afrikaans |
74
+ | ak | Akan |
75
+ | am | Amharic |
76
+ | ar | Arabic |
77
+ | ast | Asturian |
78
+ | az | Azerbaijani |
79
+ | ba | Bashkir |
80
+ | ban | Balinese |
81
+ | bax | Bamun |
82
+ | be | Belarusian |
83
+ | bg | Bulgarian |
84
+ | bku | Buhid |
85
+ | bm | Bambara |
86
+ | bn | Bangla |
87
+ | bo | Tibetan |
88
+ | bug | Buginese |
89
+ | bya | Batak |
90
+ | ca | Catalan |
91
+ | ceb | Cebuano |
92
+ | chr | Cherokee |
93
+ | ckb | Central Kurdish |
94
+ | cop | Coptic |
95
+ | cs | Czech |
96
+ | cv | Chuvash |
97
+ | da | Danish |
98
+ | de | German |
99
+ | dz | Dzongkha |
100
+ | el | Greek |
101
+ | en | English |
102
+ | eo | Esperanto |
103
+ | es | Spanish |
104
+ | et | Estonian |
105
+ | eu | Basque |
106
+ | fa | Persian |
107
+ | fi | Finnish |
108
+ | fo | Faroese |
109
+ | fr | French |
110
+ | fur | Friulian |
111
+ | ga | Irish |
112
+ | gd | Scottish Gaelic |
113
+ | gez | Geez |
114
+ | gl | Galician |
115
+ | gu | Gujarati |
116
+ | gv | Manx |
117
+ | haw | Hawaiian |
118
+ | he | Hebrew |
119
+ | hi | Hindi |
120
+ | hnn | Hanunoo |
121
+ | ht | Haitian Creole |
122
+ | hu | Hungarian |
123
+ | hy | Armenian |
124
+ | ie | Interlingue |
125
+ | is | Icelandic |
126
+ | it | Italian |
127
+ | ja | Japanese |
128
+ | jv | Javanese |
129
+ | ka | Georgian |
130
+ | kab | Kabyle |
131
+ | kk | Kazakh |
132
+ | kl | Kalaallisut |
133
+ | km | Khmer |
134
+ | kn | Kannada |
135
+ | ko | Korean |
136
+ | ks | Kashmiri |
137
+ | ksh | Colognian |
138
+ | ku | Kurdish |
139
+ | ky | Kyrgyz |
140
+ | la | Latin |
141
+ | lb | Luxembourgish |
142
+ | lep | Lepcha |
143
+ | lif | Limbu |
144
+ | lij | Ligurian |
145
+ | lis | Lisu |
146
+ | lo | Lao |
147
+ | lt | Lithuanian |
148
+ | lv | Latvian |
149
+ | mg | Malagasy |
150
+ | mid | Mandaic |
151
+ | mk | Macedonian |
152
+ | ml | Malayalam |
153
+ | mn | Mongolian |
154
+ | mo | Romanian |
155
+ | my | Burmese |
156
+ | mzn | Mazanderani |
157
+ | nds | Low German |
158
+ | ne | Nepali |
159
+ | nn | Norwegian Nynorsk |
160
+ | no | Norwegian |
161
+ | nqo | N’Ko |
162
+ | nso | Northern Sotho |
163
+ | oc | Occitan |
164
+ | or | Odia |
165
+ | pl | Polish |
166
+ | ps | Pashto |
167
+ | pt | Portuguese |
168
+ | rej | Rejang |
169
+ | rm | Romansh |
170
+ | ro | Romanian |
171
+ | ru | Russian |
172
+ | sa | Sanskrit |
173
+ | sam | Samaritan Aramaic |
174
+ | saz | Saurashtra |
175
+ | sc | Sardinian |
176
+ | se | Northern Sami |
177
+ | sg | Sango |
178
+ | si | Sinhala |
179
+ | sl | Slovenian |
180
+ | sn | Shona |
181
+ | so | Somali |
182
+ | sr | Serbian |
183
+ | su | Sundanese |
184
+ | sv | Swedish |
185
+ | syr | Syriac |
186
+ | szl | Silesian |
187
+ | ta | Tamil |
188
+ | tbw | Tagbanwa |
189
+ | te | Telugu |
190
+ | tg | Tajik |
191
+ | th | Thai |
192
+ | ti | Tigrinya |
193
+ | tk | Turkmen |
194
+ | tl | Filipino |
195
+ | tn | Tswana |
196
+ | tr | Turkish |
197
+ | tt | Tatar |
198
+ | uk | Ukrainian |
199
+ | ur | Urdu |
200
+ | vai | Vai |
201
+ | vec | Venetian |
202
+ | wo | Wolof |
203
+ | zh | Chinese |
204
+ | zh-classical | Classical Chinese |
205
+ | zh-min-nan | Min Nan Chinese |
206
+ | zh-yue | Cantonese |
207
+ | zra | Kara (Korea) |
208
+
209
+ ## Developer Guide
210
+
211
+ This project uses the
212
+ [kalenchukov/Alphabet](https://github.com/kalenchukov/Alphabet) Java repository as
213
+ the source for alphabet data. A helper script clones the repository, scans all
214
+ `*Alphabet.java` files, downloads a sample Wikipedia article for supported
215
+ languages, and writes JSON files containing the alphabet and estimated letter
216
+ frequencies. A second utility can replace those estimates with corpus
217
+ frequencies from the [Simia unigrams dataset](http://simia.net/letters/).
218
+
219
+ Each JSON file includes:
220
+
221
+ - `alphabetical` – letters of the alphabet (uppercase when the script has
222
+ case)
223
+ - `uppercase` – uppercase letters
224
+ - `lowercase` – lowercase letters
225
+ - `frequency` – relative frequency of each lowercase letter (zero when no
226
+ sample text is available)
227
+
228
+ Example JSON snippet:
229
+
230
+ ```json
231
+ {
232
+ "alphabetical": ["A", "B", ...],
233
+ "uppercase": ["A", "B", ...],
234
+ "lowercase": ["a", "b", ...],
235
+ "frequency": {"a": 0.084, "b": 0.0208, ...}
236
+ }
237
+ ```
238
+
239
+ ### Setup
240
+
241
+ This project uses `uv` for dependency management. To set up the development
242
+ environment:
243
+
244
+ ```bash
245
+ # Install uv
246
+ pipx install uv
247
+
248
+ # Create and activate a virtual environment
249
+ uv venv
250
+ source .venv/bin/activate
251
+
252
+ # Install dependencies
253
+ uv pip install -e '.[dev]'
254
+ ```
255
+
256
+ ### Data Generation
257
+
258
+ **Extract alphabets**
259
+
260
+ ```bash
261
+ uv run scripts/extract_alphabets.py
262
+ ```
263
+
264
+ The script clones the Java project and stores JSON files for every available
265
+ alphabet under `data/alphabets/`, named by ISO language code. If no sample text
266
+ is available, frequency values default to zero and the language is recorded in
267
+ `data/todo_languages.csv` for follow-up.
268
+
269
+ **Update letter frequencies**
270
+
271
+ ```bash
272
+ uv run scripts/update_frequencies.py
273
+ ```
274
+
275
+ This script downloads the `unigrams.zip` archive and rewrites each alphabet's
276
+ frequency mapping using the published counts.
277
+
278
+ **Generate alphabets from locale data**
279
+
280
+ Derive an alphabet from an ICU locale's exemplar character set:
281
+
282
+ ```bash
283
+ uv run scripts/generate_alphabet_from_locale.py <code> --locale <locale>
284
+ ```
285
+
286
+ The script writes `data/alphabets/<code>.json`, using the locale's standard
287
+ exemplar set for the base letters and populating frequency values from the
288
+ Simia unigrams dataset when available. Locales without exemplar data are
289
+ skipped.
290
+
291
+ **Generate alphabets from unigrams**
292
+
293
+ For languages present in the Simia dataset but missing here:
294
+
295
+ ```bash
296
+ uv run scripts/generate_alphabet_from_unigrams.py <code> --locale <locale> \
297
+ --block <Unicode block>
298
+ ```
299
+
300
+ The script writes `data/alphabets/<code>.json`. To list missing codes:
301
+
302
+ ```bash
303
+ uv run scripts/missing_unigram_languages.py
304
+ ```
305
+
306
+ **Generate missing alphabets**
307
+
308
+ Create alphabet files for every language in the Simia unigrams dataset that
309
+ does not yet have one:
310
+
311
+ ```bash
312
+ uv run scripts/generate_missing_alphabets.py --limit 10
313
+ ```
314
+
315
+ Omit `--limit` to process all missing languages. Each file is written under
316
+ `data/alphabets/` and combines ICU exemplar characters with Simia frequencies.
317
+
318
+ ### Linting and type checking
319
+
320
+ ```bash
321
+ ruff check .
322
+ mypy .
323
+ ```
324
+
325
+ ## Future work
326
+
327
+ - Add sample text or unigram support for more languages.
@@ -0,0 +1,27 @@
1
+ [project]
2
+ name = "worldalphabets"
3
+ version = "0.0.6"
4
+ readme = "README.md"
5
+ requires-python = ">=3.11"
6
+
7
+ dependencies = [
8
+ "langcodes>=3.3.0",
9
+ "language-data>=1.1.0",
10
+ ]
11
+
12
+ [project.optional-dependencies]
13
+ dev = [
14
+ "ruff>=0.1.0",
15
+ "mypy>=1.0.0",
16
+ "build>=0.10.0",
17
+ ]
18
+
19
+ [tool.ruff]
20
+ line-length = 88
21
+ target-version = "py311"
22
+
23
+ [tool.mypy]
24
+ python_version = "3.11"
25
+ warn_unused_configs = true
26
+ disallow_untyped_defs = true
27
+ strict_optional = true
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,30 @@
1
+ """Utilities for loading world alphabets."""
2
+ from __future__ import annotations
3
+
4
+ from dataclasses import dataclass
5
+ from pathlib import Path
6
+ import json
7
+ from typing import Dict, List
8
+
9
+ DATA_DIR = Path(__file__).resolve().parent.parent / "data" / "alphabets"
10
+
11
+
12
+ @dataclass
13
+ class Alphabet:
14
+ """Alphabet data for a language."""
15
+
16
+ alphabetical: List[str]
17
+ uppercase: List[str]
18
+ lowercase: List[str]
19
+ frequency: Dict[str, float]
20
+
21
+
22
+ def load_alphabet(code: str) -> Alphabet:
23
+ """Return alphabet information for ISO language ``code``."""
24
+
25
+ path = DATA_DIR / f"{code}.json"
26
+ data = json.loads(path.read_text(encoding="utf-8"))
27
+ return Alphabet(**data)
28
+
29
+
30
+ __all__ = ["load_alphabet", "Alphabet"]
@@ -0,0 +1,341 @@
1
+ Metadata-Version: 2.4
2
+ Name: worldalphabets
3
+ Version: 0.0.6
4
+ Requires-Python: >=3.11
5
+ Description-Content-Type: text/markdown
6
+ License-File: LICENSE
7
+ Requires-Dist: langcodes>=3.3.0
8
+ Requires-Dist: language-data>=1.1.0
9
+ Provides-Extra: dev
10
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
11
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
12
+ Requires-Dist: build>=0.10.0; extra == "dev"
13
+ Dynamic: license-file
14
+
15
+ # WorldAlphabets
16
+
17
+ A tool to access alphabets of the world with Python and Node interfaces.
18
+
19
+ ## Usage
20
+
21
+ ### Python
22
+
23
+ To load the data in Python:
24
+
25
+ ```python
26
+ from worldalphabets import load_alphabet
27
+
28
+ alphabet = load_alphabet("en")
29
+ print(alphabet.uppercase[:5]) # ['A', 'B', 'C', 'D', 'E']
30
+ print(alphabet.frequency['e'])
31
+ ```
32
+
33
+ ### Node.js
34
+
35
+ #### From npm
36
+
37
+ Install the package from npm:
38
+
39
+ ```bash
40
+ npm install worldalphabets
41
+ ```
42
+
43
+ Then, you can use the functions in your project:
44
+
45
+ ```javascript
46
+ const { getUppercase, getLowercase, getFrequency, getAvailableCodes } = require('worldalphabets');
47
+
48
+ async function main() {
49
+ const codes = await getAvailableCodes();
50
+ console.log('Available codes (first 5):', codes.slice(0, 5));
51
+
52
+ const uppercaseEn = await getUppercase('en');
53
+ console.log('English uppercase:', uppercaseEn);
54
+
55
+ const lowercaseFr = await getLowercase('fr');
56
+ console.log('French lowercase:', lowercaseFr);
57
+
58
+ const frequencyDe = await getFrequency('de');
59
+ console.log('German frequency for "a":', frequencyDe['a']);
60
+ }
61
+
62
+ main();
63
+ ```
64
+
65
+ #### Local Usage
66
+
67
+ If you have cloned the repository, you can use the module directly:
68
+
69
+ ```javascript
70
+ const { getUppercase } = require('./index');
71
+
72
+ async function main() {
73
+ const uppercaseEn = await getUppercase('en');
74
+ console.log('English uppercase:', uppercaseEn);
75
+ }
76
+
77
+ main();
78
+ ```
79
+
80
+ ## Supported Languages
81
+
82
+ Alphabet JSON files are available for these ISO language codes
83
+ (language names from [langcodes](https://pypi.org/project/langcodes/)):
84
+
85
+ | Code | Language |
86
+ |------|----------|
87
+ | af | Afrikaans |
88
+ | ak | Akan |
89
+ | am | Amharic |
90
+ | ar | Arabic |
91
+ | ast | Asturian |
92
+ | az | Azerbaijani |
93
+ | ba | Bashkir |
94
+ | ban | Balinese |
95
+ | bax | Bamun |
96
+ | be | Belarusian |
97
+ | bg | Bulgarian |
98
+ | bku | Buhid |
99
+ | bm | Bambara |
100
+ | bn | Bangla |
101
+ | bo | Tibetan |
102
+ | bug | Buginese |
103
+ | bya | Batak |
104
+ | ca | Catalan |
105
+ | ceb | Cebuano |
106
+ | chr | Cherokee |
107
+ | ckb | Central Kurdish |
108
+ | cop | Coptic |
109
+ | cs | Czech |
110
+ | cv | Chuvash |
111
+ | da | Danish |
112
+ | de | German |
113
+ | dz | Dzongkha |
114
+ | el | Greek |
115
+ | en | English |
116
+ | eo | Esperanto |
117
+ | es | Spanish |
118
+ | et | Estonian |
119
+ | eu | Basque |
120
+ | fa | Persian |
121
+ | fi | Finnish |
122
+ | fo | Faroese |
123
+ | fr | French |
124
+ | fur | Friulian |
125
+ | ga | Irish |
126
+ | gd | Scottish Gaelic |
127
+ | gez | Geez |
128
+ | gl | Galician |
129
+ | gu | Gujarati |
130
+ | gv | Manx |
131
+ | haw | Hawaiian |
132
+ | he | Hebrew |
133
+ | hi | Hindi |
134
+ | hnn | Hanunoo |
135
+ | ht | Haitian Creole |
136
+ | hu | Hungarian |
137
+ | hy | Armenian |
138
+ | ie | Interlingue |
139
+ | is | Icelandic |
140
+ | it | Italian |
141
+ | ja | Japanese |
142
+ | jv | Javanese |
143
+ | ka | Georgian |
144
+ | kab | Kabyle |
145
+ | kk | Kazakh |
146
+ | kl | Kalaallisut |
147
+ | km | Khmer |
148
+ | kn | Kannada |
149
+ | ko | Korean |
150
+ | ks | Kashmiri |
151
+ | ksh | Colognian |
152
+ | ku | Kurdish |
153
+ | ky | Kyrgyz |
154
+ | la | Latin |
155
+ | lb | Luxembourgish |
156
+ | lep | Lepcha |
157
+ | lif | Limbu |
158
+ | lij | Ligurian |
159
+ | lis | Lisu |
160
+ | lo | Lao |
161
+ | lt | Lithuanian |
162
+ | lv | Latvian |
163
+ | mg | Malagasy |
164
+ | mid | Mandaic |
165
+ | mk | Macedonian |
166
+ | ml | Malayalam |
167
+ | mn | Mongolian |
168
+ | mo | Romanian |
169
+ | my | Burmese |
170
+ | mzn | Mazanderani |
171
+ | nds | Low German |
172
+ | ne | Nepali |
173
+ | nn | Norwegian Nynorsk |
174
+ | no | Norwegian |
175
+ | nqo | N’Ko |
176
+ | nso | Northern Sotho |
177
+ | oc | Occitan |
178
+ | or | Odia |
179
+ | pl | Polish |
180
+ | ps | Pashto |
181
+ | pt | Portuguese |
182
+ | rej | Rejang |
183
+ | rm | Romansh |
184
+ | ro | Romanian |
185
+ | ru | Russian |
186
+ | sa | Sanskrit |
187
+ | sam | Samaritan Aramaic |
188
+ | saz | Saurashtra |
189
+ | sc | Sardinian |
190
+ | se | Northern Sami |
191
+ | sg | Sango |
192
+ | si | Sinhala |
193
+ | sl | Slovenian |
194
+ | sn | Shona |
195
+ | so | Somali |
196
+ | sr | Serbian |
197
+ | su | Sundanese |
198
+ | sv | Swedish |
199
+ | syr | Syriac |
200
+ | szl | Silesian |
201
+ | ta | Tamil |
202
+ | tbw | Tagbanwa |
203
+ | te | Telugu |
204
+ | tg | Tajik |
205
+ | th | Thai |
206
+ | ti | Tigrinya |
207
+ | tk | Turkmen |
208
+ | tl | Filipino |
209
+ | tn | Tswana |
210
+ | tr | Turkish |
211
+ | tt | Tatar |
212
+ | uk | Ukrainian |
213
+ | ur | Urdu |
214
+ | vai | Vai |
215
+ | vec | Venetian |
216
+ | wo | Wolof |
217
+ | zh | Chinese |
218
+ | zh-classical | Classical Chinese |
219
+ | zh-min-nan | Min Nan Chinese |
220
+ | zh-yue | Cantonese |
221
+ | zra | Kara (Korea) |
222
+
223
+ ## Developer Guide
224
+
225
+ This project uses the
226
+ [kalenchukov/Alphabet](https://github.com/kalenchukov/Alphabet) Java repository as
227
+ the source for alphabet data. A helper script clones the repository, scans all
228
+ `*Alphabet.java` files, downloads a sample Wikipedia article for supported
229
+ languages, and writes JSON files containing the alphabet and estimated letter
230
+ frequencies. A second utility can replace those estimates with corpus
231
+ frequencies from the [Simia unigrams dataset](http://simia.net/letters/).
232
+
233
+ Each JSON file includes:
234
+
235
+ - `alphabetical` – letters of the alphabet (uppercase when the script has
236
+ case)
237
+ - `uppercase` – uppercase letters
238
+ - `lowercase` – lowercase letters
239
+ - `frequency` – relative frequency of each lowercase letter (zero when no
240
+ sample text is available)
241
+
242
+ Example JSON snippet:
243
+
244
+ ```json
245
+ {
246
+ "alphabetical": ["A", "B", ...],
247
+ "uppercase": ["A", "B", ...],
248
+ "lowercase": ["a", "b", ...],
249
+ "frequency": {"a": 0.084, "b": 0.0208, ...}
250
+ }
251
+ ```
252
+
253
+ ### Setup
254
+
255
+ This project uses `uv` for dependency management. To set up the development
256
+ environment:
257
+
258
+ ```bash
259
+ # Install uv
260
+ pipx install uv
261
+
262
+ # Create and activate a virtual environment
263
+ uv venv
264
+ source .venv/bin/activate
265
+
266
+ # Install dependencies
267
+ uv pip install -e '.[dev]'
268
+ ```
269
+
270
+ ### Data Generation
271
+
272
+ **Extract alphabets**
273
+
274
+ ```bash
275
+ uv run scripts/extract_alphabets.py
276
+ ```
277
+
278
+ The script clones the Java project and stores JSON files for every available
279
+ alphabet under `data/alphabets/`, named by ISO language code. If no sample text
280
+ is available, frequency values default to zero and the language is recorded in
281
+ `data/todo_languages.csv` for follow-up.
282
+
283
+ **Update letter frequencies**
284
+
285
+ ```bash
286
+ uv run scripts/update_frequencies.py
287
+ ```
288
+
289
+ This script downloads the `unigrams.zip` archive and rewrites each alphabet's
290
+ frequency mapping using the published counts.
291
+
292
+ **Generate alphabets from locale data**
293
+
294
+ Derive an alphabet from an ICU locale's exemplar character set:
295
+
296
+ ```bash
297
+ uv run scripts/generate_alphabet_from_locale.py <code> --locale <locale>
298
+ ```
299
+
300
+ The script writes `data/alphabets/<code>.json`, using the locale's standard
301
+ exemplar set for the base letters and populating frequency values from the
302
+ Simia unigrams dataset when available. Locales without exemplar data are
303
+ skipped.
304
+
305
+ **Generate alphabets from unigrams**
306
+
307
+ For languages present in the Simia dataset but missing here:
308
+
309
+ ```bash
310
+ uv run scripts/generate_alphabet_from_unigrams.py <code> --locale <locale> \
311
+ --block <Unicode block>
312
+ ```
313
+
314
+ The script writes `data/alphabets/<code>.json`. To list missing codes:
315
+
316
+ ```bash
317
+ uv run scripts/missing_unigram_languages.py
318
+ ```
319
+
320
+ **Generate missing alphabets**
321
+
322
+ Create alphabet files for every language in the Simia unigrams dataset that
323
+ does not yet have one:
324
+
325
+ ```bash
326
+ uv run scripts/generate_missing_alphabets.py --limit 10
327
+ ```
328
+
329
+ Omit `--limit` to process all missing languages. Each file is written under
330
+ `data/alphabets/` and combines ICU exemplar characters with Simia frequencies.
331
+
332
+ ### Linting and type checking
333
+
334
+ ```bash
335
+ ruff check .
336
+ mypy .
337
+ ```
338
+
339
+ ## Future work
340
+
341
+ - Add sample text or unigram support for more languages.
@@ -0,0 +1,9 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/worldalphabets/__init__.py
5
+ src/worldalphabets.egg-info/PKG-INFO
6
+ src/worldalphabets.egg-info/SOURCES.txt
7
+ src/worldalphabets.egg-info/dependency_links.txt
8
+ src/worldalphabets.egg-info/requires.txt
9
+ src/worldalphabets.egg-info/top_level.txt
@@ -0,0 +1,7 @@
1
+ langcodes>=3.3.0
2
+ language-data>=1.1.0
3
+
4
+ [dev]
5
+ ruff>=0.1.0
6
+ mypy>=1.0.0
7
+ build>=0.10.0
@@ -0,0 +1 @@
1
+ worldalphabets