turkic-translit 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- turkic_translit-0.2.0/LICENSE +21 -0
- turkic_translit-0.2.0/PKG-INFO +253 -0
- turkic_translit-0.2.0/README.md +189 -0
- turkic_translit-0.2.0/pyproject.toml +139 -0
- turkic_translit-0.2.0/setup.cfg +4 -0
- turkic_translit-0.2.0/src/turkic_translit/__init__.py +53 -0
- turkic_translit-0.2.0/src/turkic_translit/cli/__init__.py +59 -0
- turkic_translit-0.2.0/src/turkic_translit/cli/_net_utils.py +16 -0
- turkic_translit-0.2.0/src/turkic_translit/cli/build_spm.py +59 -0
- turkic_translit-0.2.0/src/turkic_translit/cli/corpora.yaml +7 -0
- turkic_translit-0.2.0/src/turkic_translit/cli/download_corpus.py +365 -0
- turkic_translit-0.2.0/src/turkic_translit/cli/eval_lm.py +28 -0
- turkic_translit-0.2.0/src/turkic_translit/cli/filter_russian.py +178 -0
- turkic_translit-0.2.0/src/turkic_translit/cli/pyicu_install.py +84 -0
- turkic_translit-0.2.0/src/turkic_translit/cli/run_leven.py +31 -0
- turkic_translit-0.2.0/src/turkic_translit/cli/train_lm.py +47 -0
- turkic_translit-0.2.0/src/turkic_translit/cli/train_spm.py +164 -0
- turkic_translit-0.2.0/src/turkic_translit/cli.py +331 -0
- turkic_translit-0.2.0/src/turkic_translit/core.py +64 -0
- turkic_translit-0.2.0/src/turkic_translit/lang_filter.py +77 -0
- turkic_translit-0.2.0/src/turkic_translit/lang_utils.py +38 -0
- turkic_translit-0.2.0/src/turkic_translit/langid.py +50 -0
- turkic_translit-0.2.0/src/turkic_translit/lm/__init__.py +17 -0
- turkic_translit-0.2.0/src/turkic_translit/lm/data.py +73 -0
- turkic_translit-0.2.0/src/turkic_translit/lm/eval.py +25 -0
- turkic_translit-0.2.0/src/turkic_translit/lm/similarity.py +53 -0
- turkic_translit-0.2.0/src/turkic_translit/lm/tokenizer.py +31 -0
- turkic_translit-0.2.0/src/turkic_translit/lm/train.py +118 -0
- turkic_translit-0.2.0/src/turkic_translit/logging_config.py +61 -0
- turkic_translit-0.2.0/src/turkic_translit/model_utils.py +133 -0
- turkic_translit-0.2.0/src/turkic_translit/patches.py +92 -0
- turkic_translit-0.2.0/src/turkic_translit/pipeline.py +33 -0
- turkic_translit-0.2.0/src/turkic_translit/rules/ar_lat.rules +15 -0
- turkic_translit-0.2.0/src/turkic_translit/rules/kk_ipa.rules +72 -0
- turkic_translit-0.2.0/src/turkic_translit/rules/kk_lat2023.rules +49 -0
- turkic_translit-0.2.0/src/turkic_translit/rules/ky_ipa.rules +60 -0
- turkic_translit-0.2.0/src/turkic_translit/rules/ky_lat2023.rules +40 -0
- turkic_translit-0.2.0/src/turkic_translit/sanity.py +34 -0
- turkic_translit-0.2.0/src/turkic_translit/tokenizer.py +26 -0
- turkic_translit-0.2.0/src/turkic_translit/transliterate.py +18 -0
- turkic_translit-0.2.0/src/turkic_translit/web/__init__.py +0 -0
- turkic_translit-0.2.0/src/turkic_translit/web/web_demo.py +1240 -0
- turkic_translit-0.2.0/src/turkic_translit/web/web_utils.py +473 -0
- turkic_translit-0.2.0/src/turkic_translit.egg-info/PKG-INFO +253 -0
- turkic_translit-0.2.0/src/turkic_translit.egg-info/SOURCES.txt +62 -0
- turkic_translit-0.2.0/src/turkic_translit.egg-info/dependency_links.txt +1 -0
- turkic_translit-0.2.0/src/turkic_translit.egg-info/entry_points.txt +11 -0
- turkic_translit-0.2.0/src/turkic_translit.egg-info/requires.txt +48 -0
- turkic_translit-0.2.0/src/turkic_translit.egg-info/top_level.txt +1 -0
- turkic_translit-0.2.0/tests/test_cli.py +36 -0
- turkic_translit-0.2.0/tests/test_cli_lm.py +141 -0
- turkic_translit-0.2.0/tests/test_download_corpus.py +167 -0
- turkic_translit-0.2.0/tests/test_fasttext.py +24 -0
- turkic_translit-0.2.0/tests/test_kazakh_ipa_letters.py +55 -0
- turkic_translit-0.2.0/tests/test_kazakh_northwind.py +34 -0
- turkic_translit-0.2.0/tests/test_kyrgyz_ipa_letters.py +53 -0
- turkic_translit-0.2.0/tests/test_kyrgyz_words_mccollum.py +61 -0
- turkic_translit-0.2.0/tests/test_lang_filter.py +263 -0
- turkic_translit-0.2.0/tests/test_lang_filter_new.py +236 -0
- turkic_translit-0.2.0/tests/test_links_alive.py +20 -0
- turkic_translit-0.2.0/tests/test_model_utils.py +243 -0
- turkic_translit-0.2.0/tests/test_train_spm.py +71 -0
- turkic_translit-0.2.0/tests/test_translit.py +22 -0
- turkic_translit-0.2.0/tests/test_verification.py +265 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Austin Wagner
|
|
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,253 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: turkic-translit
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Deterministic Latin and IPA transliteration for Kazakh, Kyrgyz, plus tokenizer/glue scripts.
|
|
5
|
+
Author-email: Austin Wagner <austinwagner@msn.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: kazakh,kyrgyz,transliteration,ipa
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: epitran<1.27,>=1.0
|
|
22
|
+
Requires-Dist: fasttext-wheel==0.9.2
|
|
23
|
+
Requires-Dist: numpy<2
|
|
24
|
+
Requires-Dist: packaging>=23.0
|
|
25
|
+
Requires-Dist: panphon<0.22,>=0.20
|
|
26
|
+
Requires-Dist: PyICU<2.16,>=2.13; sys_platform != "win32"
|
|
27
|
+
Requires-Dist: pytest>=8.0
|
|
28
|
+
Requires-Dist: rapidfuzz>=3.5
|
|
29
|
+
Requires-Dist: rich>=13.7
|
|
30
|
+
Requires-Dist: sentencepiece>=0.2.0
|
|
31
|
+
Requires-Dist: click>=8.1
|
|
32
|
+
Requires-Dist: types-requests>=2.31
|
|
33
|
+
Requires-Dist: datasets<4.0.0,>=3.6.0
|
|
34
|
+
Requires-Dist: evaluate>=0.4
|
|
35
|
+
Requires-Dist: accelerate>=0.28
|
|
36
|
+
Requires-Dist: transformers<5,>=4.41
|
|
37
|
+
Requires-Dist: tqdm>=4.66
|
|
38
|
+
Requires-Dist: scikit-learn>=1.4
|
|
39
|
+
Requires-Dist: typing_extensions>=4.12
|
|
40
|
+
Requires-Dist: wikipedia<2.0.0,>=1.4.0
|
|
41
|
+
Requires-Dist: gradio>=4.0
|
|
42
|
+
Requires-Dist: pandas
|
|
43
|
+
Requires-Dist: matplotlib>=3.9
|
|
44
|
+
Requires-Dist: pycountry>=23.12
|
|
45
|
+
Provides-Extra: examples
|
|
46
|
+
Requires-Dist: flask; extra == "examples"
|
|
47
|
+
Requires-Dist: streamlit; extra == "examples"
|
|
48
|
+
Requires-Dist: jupyterlab; extra == "examples"
|
|
49
|
+
Provides-Extra: winlid
|
|
50
|
+
Provides-Extra: corpus
|
|
51
|
+
Requires-Dist: datasets>=3.0; extra == "corpus"
|
|
52
|
+
Requires-Dist: pyarrow>=14.0; extra == "corpus"
|
|
53
|
+
Requires-Dist: requests>=2.0; extra == "corpus"
|
|
54
|
+
Requires-Dist: zstandard>=0.23; extra == "corpus"
|
|
55
|
+
Provides-Extra: dev
|
|
56
|
+
Requires-Dist: ruff>=0.2.0; extra == "dev"
|
|
57
|
+
Requires-Dist: mypy>=1.0; extra == "dev"
|
|
58
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
59
|
+
Requires-Dist: build>=1.0; extra == "dev"
|
|
60
|
+
Requires-Dist: twine>=4.0; extra == "dev"
|
|
61
|
+
Requires-Dist: make>=0.1.6; extra == "dev"
|
|
62
|
+
Requires-Dist: types-requests>=2.31; extra == "dev"
|
|
63
|
+
Dynamic: license-file
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
title: Turkic Transliteration Demo
|
|
67
|
+
emoji: 🌖
|
|
68
|
+
colorFrom: green
|
|
69
|
+
colorTo: green
|
|
70
|
+
sdk: gradio
|
|
71
|
+
sdk_version: 5.29.0
|
|
72
|
+
app_file: app.py
|
|
73
|
+
pinned: false
|
|
74
|
+
license: apache-2.0
|
|
75
|
+
short_description: Transliteration of Kazakh & Kyrgyz into Latin and IPA
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
turkic\_transliterate
|
|
79
|
+
Deterministic Latin and IPA transliteration for Kazakh and Kyrgyz, plus helper utilities for tokenizer training and Russian-token filtering.
|
|
80
|
+
|
|
81
|
+
Quick install
|
|
82
|
+
|
|
83
|
+
1. Install Miniconda or Anaconda (recommended).
|
|
84
|
+
2. Clone the repo and create the environment:
|
|
85
|
+
conda env create -f env.yml
|
|
86
|
+
3. Activate the environment:
|
|
87
|
+
conda activate turkic
|
|
88
|
+
4. Run the verification tests:
|
|
89
|
+
python -m pytest (all tests should pass)
|
|
90
|
+
|
|
91
|
+
Python compatibility
|
|
92
|
+
• Works on CPython 3.10 and 3.11.
|
|
93
|
+
• CPython 3.12+ is supported everywhere except on Windows until official PyICU wheels are available; see “Windows & PyICU” below.
|
|
94
|
+
|
|
95
|
+
Package names
|
|
96
|
+
• Runtime import path: turkic\_translit
|
|
97
|
+
• Distributable name on PyPI: turkic\_transliterate
|
|
98
|
+
• Command-line entry point: turkic-translit
|
|
99
|
+
|
|
100
|
+
## Developer Setup
|
|
101
|
+
|
|
102
|
+
For the simplest developer setup experience, run the setup script:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
python scripts/setup_dev.py
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
This script will:
|
|
109
|
+
1. Install the package with all development dependencies
|
|
110
|
+
2. Set up PyICU on Windows automatically
|
|
111
|
+
3. Verify that development tools are working properly
|
|
112
|
+
|
|
113
|
+
### Manual Installation
|
|
114
|
+
|
|
115
|
+
Alternatively, install with pip:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
pip install -e .[dev,ui] # add ,winlid on Windows if you need fasttext-wheel
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Development Tools
|
|
122
|
+
|
|
123
|
+
#### Linux/macOS/Windows with GNU Make
|
|
124
|
+
|
|
125
|
+
If you have GNU Make installed, you can use the Makefile for common tasks:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
make lint # Run linting (ruff, black, mypy)
|
|
129
|
+
make format # Auto-format code
|
|
130
|
+
make test # Run tests
|
|
131
|
+
make web # Launch the web UI
|
|
132
|
+
make help # Show all available commands
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
#### Windows
|
|
136
|
+
|
|
137
|
+
**Option 1: Install GNU Make using Chocolatey (Recommended)**
|
|
138
|
+
|
|
139
|
+
Install GNU Make using Chocolatey (requires admin privileges):
|
|
140
|
+
|
|
141
|
+
```powershell
|
|
142
|
+
# In an Admin PowerShell window
|
|
143
|
+
choco install make
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
After installation, you can use the same `make` commands as on Linux/macOS.
|
|
147
|
+
|
|
148
|
+
**Option 2: Use the PowerShell Script Alternative**
|
|
149
|
+
|
|
150
|
+
If you prefer not to install Chocolatey or GNU Make, use the PowerShell script:
|
|
151
|
+
|
|
152
|
+
```powershell
|
|
153
|
+
./scripts/run.ps1 lint # Run linting
|
|
154
|
+
./scripts/run.ps1 format # Auto-format code
|
|
155
|
+
./scripts/run.ps1 test # Run tests
|
|
156
|
+
./scripts/run.ps1 web # Launch the web UI
|
|
157
|
+
./scripts/run.ps1 help # Show all available commands
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Optional extras
|
|
161
|
+
dev → black, ruff, pytest
|
|
162
|
+
ui → gradio web demo
|
|
163
|
+
winlid (Windows only) → fasttext-wheel for language ID
|
|
164
|
+
|
|
165
|
+
Windows & PyICU
|
|
166
|
+
|
|
167
|
+
**Important:** Due to PyPI rules, the correct PyICU wheel for Windows cannot be installed automatically during pip install. After installing this package with pip, Windows users must run the helper script to install the appropriate PyICU wheel:
|
|
168
|
+
|
|
169
|
+
turkic-pyicu-install
|
|
170
|
+
|
|
171
|
+
This script will download and install the correct PyICU wheel from Christoph Gohlke’s repository based on your Python version. See the script for details.
|
|
172
|
+
|
|
173
|
+
Command-line usage
|
|
174
|
+
turkic-translit --lang kk --in text.txt --out\_latin kk\_lat.txt --ipa --out\_ipa kk\_ipa.txt --arabic --log-level debug
|
|
175
|
+
• --lang kk or ky
|
|
176
|
+
• --ipa emit IPA alongside Latin
|
|
177
|
+
• --arabic also transliterate embedded Arabic script
|
|
178
|
+
• --benchmark print throughput statistics
|
|
179
|
+
• --log-level debug | info | warning | error | critical (default: info)
|
|
180
|
+
|
|
181
|
+
Logging
|
|
182
|
+
The central logging setup uses Rich for colour when available.
|
|
183
|
+
Set TURKIC\_LOG\_LEVEL or pass --log-level to the CLI.
|
|
184
|
+
Fallback to standard logging when Rich is absent.
|
|
185
|
+
|
|
186
|
+
# Project Organization
|
|
187
|
+
|
|
188
|
+
The project is organized into the following directories:
|
|
189
|
+
|
|
190
|
+
- `src/turkic_translit/` - Core source code for the package
|
|
191
|
+
- `examples/` - Example scripts showing how to use the package
|
|
192
|
+
- `examples/web/` - Web interface for demonstrating transliteration features
|
|
193
|
+
- `data/` - Sample data files and language resources
|
|
194
|
+
- `docs/` - Documentation and reference materials
|
|
195
|
+
- `scripts/` - Utility scripts for development and release
|
|
196
|
+
- `scripts/release/` - Scripts for building and publishing packages
|
|
197
|
+
- `vendor/pyicu/` - Pre-built PyICU wheels for Windows
|
|
198
|
+
- `tests/` - Test suite for the package
|
|
199
|
+
|
|
200
|
+
## FastText Language Identification Model
|
|
201
|
+
|
|
202
|
+
This package uses the [FastText language identification model](https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.bin) (`lid.176.bin`) for Russian token filtering and language detection. **The model file is not included in the repository or pip package due to its large size.**
|
|
203
|
+
|
|
204
|
+
**Automatic Download:**
|
|
205
|
+
- When you use features that require language identification (such as Russian token filtering or the Gradio web demo), the package will automatically download `lid.176.bin` from the official Facebook AI public link if it is not already present.
|
|
206
|
+
- The file will be saved in the package directory on first use.
|
|
207
|
+
|
|
208
|
+
**No manual action is needed.** This ensures compatibility with pip installs, Hugging Face Spaces, and other cloud environments.
|
|
209
|
+
|
|
210
|
+
If you need to download the model manually, you can do so from:
|
|
211
|
+
https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.bin
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
## Using the Examples
|
|
215
|
+
|
|
216
|
+
Use the main entry point script to run examples:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
python turkic_tools.py [command]
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Available commands:
|
|
223
|
+
- `web` - Launch the Gradio web interface for real-time transliteration
|
|
224
|
+
- `demo` - Run the simple CLI demo
|
|
225
|
+
- `full-demo` - Run the comprehensive demo with multiple languages
|
|
226
|
+
- `help` - Display available commands
|
|
227
|
+
|
|
228
|
+
Tokenizer training example
|
|
229
|
+
turkic-build-spm --input corpora/kk\_lat.txt,corpora/ky\_lat.txt --model\_prefix spm/turkic12k --vocab\_size 12000
|
|
230
|
+
|
|
231
|
+
Filtering Russian tokens from Uzbek
|
|
232
|
+
cat uz\_raw\.txt | turkic-filter-russian --mode drop > uz\_clean.txt
|
|
233
|
+
|
|
234
|
+
Developer checklist
|
|
235
|
+
black .
|
|
236
|
+
ruff check .
|
|
237
|
+
pytest -q
|
|
238
|
+
|
|
239
|
+
All code is UTF-8-only; on Windows a BOM is written when piping to files to avoid encoding issues.
|
|
240
|
+
|
|
241
|
+
License
|
|
242
|
+
Apache-2.0
|
|
243
|
+
|
|
244
|
+
### Type-checking
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
pip install mypy
|
|
248
|
+
mypy --strict .
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
The included mypy.ini restricts analysis to the src/ tree and skips
|
|
252
|
+
build/, dist/, virtual-env and egg directories so duplicate-module
|
|
253
|
+
errors do not occur even if you build wheels locally.
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Turkic Transliteration Demo
|
|
3
|
+
emoji: 🌖
|
|
4
|
+
colorFrom: green
|
|
5
|
+
colorTo: green
|
|
6
|
+
sdk: gradio
|
|
7
|
+
sdk_version: 5.29.0
|
|
8
|
+
app_file: app.py
|
|
9
|
+
pinned: false
|
|
10
|
+
license: apache-2.0
|
|
11
|
+
short_description: Transliteration of Kazakh & Kyrgyz into Latin and IPA
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
turkic\_transliterate
|
|
15
|
+
Deterministic Latin and IPA transliteration for Kazakh and Kyrgyz, plus helper utilities for tokenizer training and Russian-token filtering.
|
|
16
|
+
|
|
17
|
+
Quick install
|
|
18
|
+
|
|
19
|
+
1. Install Miniconda or Anaconda (recommended).
|
|
20
|
+
2. Clone the repo and create the environment:
|
|
21
|
+
conda env create -f env.yml
|
|
22
|
+
3. Activate the environment:
|
|
23
|
+
conda activate turkic
|
|
24
|
+
4. Run the verification tests:
|
|
25
|
+
python -m pytest (all tests should pass)
|
|
26
|
+
|
|
27
|
+
Python compatibility
|
|
28
|
+
• Works on CPython 3.10 and 3.11.
|
|
29
|
+
• CPython 3.12+ is supported everywhere except on Windows until official PyICU wheels are available; see “Windows & PyICU” below.
|
|
30
|
+
|
|
31
|
+
Package names
|
|
32
|
+
• Runtime import path: turkic\_translit
|
|
33
|
+
• Distributable name on PyPI: turkic\_transliterate
|
|
34
|
+
• Command-line entry point: turkic-translit
|
|
35
|
+
|
|
36
|
+
## Developer Setup
|
|
37
|
+
|
|
38
|
+
For the simplest developer setup experience, run the setup script:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
python scripts/setup_dev.py
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
This script will:
|
|
45
|
+
1. Install the package with all development dependencies
|
|
46
|
+
2. Set up PyICU on Windows automatically
|
|
47
|
+
3. Verify that development tools are working properly
|
|
48
|
+
|
|
49
|
+
### Manual Installation
|
|
50
|
+
|
|
51
|
+
Alternatively, install with pip:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install -e .[dev,ui] # add ,winlid on Windows if you need fasttext-wheel
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Development Tools
|
|
58
|
+
|
|
59
|
+
#### Linux/macOS/Windows with GNU Make
|
|
60
|
+
|
|
61
|
+
If you have GNU Make installed, you can use the Makefile for common tasks:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
make lint # Run linting (ruff, black, mypy)
|
|
65
|
+
make format # Auto-format code
|
|
66
|
+
make test # Run tests
|
|
67
|
+
make web # Launch the web UI
|
|
68
|
+
make help # Show all available commands
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### Windows
|
|
72
|
+
|
|
73
|
+
**Option 1: Install GNU Make using Chocolatey (Recommended)**
|
|
74
|
+
|
|
75
|
+
Install GNU Make using Chocolatey (requires admin privileges):
|
|
76
|
+
|
|
77
|
+
```powershell
|
|
78
|
+
# In an Admin PowerShell window
|
|
79
|
+
choco install make
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
After installation, you can use the same `make` commands as on Linux/macOS.
|
|
83
|
+
|
|
84
|
+
**Option 2: Use the PowerShell Script Alternative**
|
|
85
|
+
|
|
86
|
+
If you prefer not to install Chocolatey or GNU Make, use the PowerShell script:
|
|
87
|
+
|
|
88
|
+
```powershell
|
|
89
|
+
./scripts/run.ps1 lint # Run linting
|
|
90
|
+
./scripts/run.ps1 format # Auto-format code
|
|
91
|
+
./scripts/run.ps1 test # Run tests
|
|
92
|
+
./scripts/run.ps1 web # Launch the web UI
|
|
93
|
+
./scripts/run.ps1 help # Show all available commands
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Optional extras
|
|
97
|
+
dev → black, ruff, pytest
|
|
98
|
+
ui → gradio web demo
|
|
99
|
+
winlid (Windows only) → fasttext-wheel for language ID
|
|
100
|
+
|
|
101
|
+
Windows & PyICU
|
|
102
|
+
|
|
103
|
+
**Important:** Due to PyPI rules, the correct PyICU wheel for Windows cannot be installed automatically during pip install. After installing this package with pip, Windows users must run the helper script to install the appropriate PyICU wheel:
|
|
104
|
+
|
|
105
|
+
turkic-pyicu-install
|
|
106
|
+
|
|
107
|
+
This script will download and install the correct PyICU wheel from Christoph Gohlke’s repository based on your Python version. See the script for details.
|
|
108
|
+
|
|
109
|
+
Command-line usage
|
|
110
|
+
turkic-translit --lang kk --in text.txt --out\_latin kk\_lat.txt --ipa --out\_ipa kk\_ipa.txt --arabic --log-level debug
|
|
111
|
+
• --lang kk or ky
|
|
112
|
+
• --ipa emit IPA alongside Latin
|
|
113
|
+
• --arabic also transliterate embedded Arabic script
|
|
114
|
+
• --benchmark print throughput statistics
|
|
115
|
+
• --log-level debug | info | warning | error | critical (default: info)
|
|
116
|
+
|
|
117
|
+
Logging
|
|
118
|
+
The central logging setup uses Rich for colour when available.
|
|
119
|
+
Set TURKIC\_LOG\_LEVEL or pass --log-level to the CLI.
|
|
120
|
+
Fallback to standard logging when Rich is absent.
|
|
121
|
+
|
|
122
|
+
# Project Organization
|
|
123
|
+
|
|
124
|
+
The project is organized into the following directories:
|
|
125
|
+
|
|
126
|
+
- `src/turkic_translit/` - Core source code for the package
|
|
127
|
+
- `examples/` - Example scripts showing how to use the package
|
|
128
|
+
- `examples/web/` - Web interface for demonstrating transliteration features
|
|
129
|
+
- `data/` - Sample data files and language resources
|
|
130
|
+
- `docs/` - Documentation and reference materials
|
|
131
|
+
- `scripts/` - Utility scripts for development and release
|
|
132
|
+
- `scripts/release/` - Scripts for building and publishing packages
|
|
133
|
+
- `vendor/pyicu/` - Pre-built PyICU wheels for Windows
|
|
134
|
+
- `tests/` - Test suite for the package
|
|
135
|
+
|
|
136
|
+
## FastText Language Identification Model
|
|
137
|
+
|
|
138
|
+
This package uses the [FastText language identification model](https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.bin) (`lid.176.bin`) for Russian token filtering and language detection. **The model file is not included in the repository or pip package due to its large size.**
|
|
139
|
+
|
|
140
|
+
**Automatic Download:**
|
|
141
|
+
- When you use features that require language identification (such as Russian token filtering or the Gradio web demo), the package will automatically download `lid.176.bin` from the official Facebook AI public link if it is not already present.
|
|
142
|
+
- The file will be saved in the package directory on first use.
|
|
143
|
+
|
|
144
|
+
**No manual action is needed.** This ensures compatibility with pip installs, Hugging Face Spaces, and other cloud environments.
|
|
145
|
+
|
|
146
|
+
If you need to download the model manually, you can do so from:
|
|
147
|
+
https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.bin
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
## Using the Examples
|
|
151
|
+
|
|
152
|
+
Use the main entry point script to run examples:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
python turkic_tools.py [command]
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Available commands:
|
|
159
|
+
- `web` - Launch the Gradio web interface for real-time transliteration
|
|
160
|
+
- `demo` - Run the simple CLI demo
|
|
161
|
+
- `full-demo` - Run the comprehensive demo with multiple languages
|
|
162
|
+
- `help` - Display available commands
|
|
163
|
+
|
|
164
|
+
Tokenizer training example
|
|
165
|
+
turkic-build-spm --input corpora/kk\_lat.txt,corpora/ky\_lat.txt --model\_prefix spm/turkic12k --vocab\_size 12000
|
|
166
|
+
|
|
167
|
+
Filtering Russian tokens from Uzbek
|
|
168
|
+
cat uz\_raw\.txt | turkic-filter-russian --mode drop > uz\_clean.txt
|
|
169
|
+
|
|
170
|
+
Developer checklist
|
|
171
|
+
black .
|
|
172
|
+
ruff check .
|
|
173
|
+
pytest -q
|
|
174
|
+
|
|
175
|
+
All code is UTF-8-only; on Windows a BOM is written when piping to files to avoid encoding issues.
|
|
176
|
+
|
|
177
|
+
License
|
|
178
|
+
Apache-2.0
|
|
179
|
+
|
|
180
|
+
### Type-checking
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
pip install mypy
|
|
184
|
+
mypy --strict .
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
The included mypy.ini restricts analysis to the src/ tree and skips
|
|
188
|
+
build/, dist/, virtual-env and egg directories so duplicate-module
|
|
189
|
+
errors do not occur even if you build wheels locally.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
[project]
|
|
7
|
+
name = "turkic-translit"
|
|
8
|
+
version = "0.2.0"
|
|
9
|
+
description = "Deterministic Latin and IPA transliteration for Kazakh, Kyrgyz, plus tokenizer/glue scripts."
|
|
10
|
+
authors = [ {name="Austin Wagner", email="austinwagner@msn.com"} ]
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = "MIT"
|
|
14
|
+
keywords = ["kazakh", "kyrgyz", "transliteration", "ipa"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.10",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
"Intended Audience :: Developers",
|
|
23
|
+
"Intended Audience :: Science/Research",
|
|
24
|
+
"Topic :: Software Development :: Libraries",
|
|
25
|
+
"Topic :: Text Processing :: Linguistic"
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
dependencies = [
|
|
29
|
+
# Core dependencies (alphabetized)
|
|
30
|
+
"epitran>=1.0,<1.27", # 1.26.0 is the latest on PyPI
|
|
31
|
+
# Universal fasttext-wheel for all platforms and Python 3.10-3.13
|
|
32
|
+
"fasttext-wheel==0.9.2",
|
|
33
|
+
"numpy<2",
|
|
34
|
+
"packaging>=23.0", # Used in tests/test_fasttext.py
|
|
35
|
+
"panphon>=0.20,<0.22", # 0.21.2 is the newest published wheel
|
|
36
|
+
# PyICU is required, but Windows users must install the correct wheel manually. See README and turkic-pyicu-install for help.
|
|
37
|
+
# PyICU wheels: pre-built for Windows versions, fallback to PyPI elsewhere
|
|
38
|
+
|
|
39
|
+
"PyICU>=2.13,<2.16; sys_platform != 'win32'",
|
|
40
|
+
"pytest>=8.0", # Test runner
|
|
41
|
+
"rapidfuzz>=3.5",
|
|
42
|
+
"rich>=13.7", # Color-aware logging and console output
|
|
43
|
+
"sentencepiece>=0.2.0",
|
|
44
|
+
"click>=8.1",
|
|
45
|
+
"types-requests>=2.31",
|
|
46
|
+
"datasets (>=3.6.0,<4.0.0)",
|
|
47
|
+
"evaluate>=0.4", # PPL metric
|
|
48
|
+
"accelerate>=0.28", # HF Trainer device dispatch
|
|
49
|
+
"transformers>=4.41,<5", # mGPT / BLOOM causal LM
|
|
50
|
+
"tqdm>=4.66", # progress bars for LM utilities
|
|
51
|
+
"scikit-learn>=1.4", # cosine similarity utilities
|
|
52
|
+
"typing_extensions>=4.12", # for Never on Python ≤3.11
|
|
53
|
+
"wikipedia (>=1.4.0,<2.0.0)",
|
|
54
|
+
# UI dependencies
|
|
55
|
+
"gradio>=4.0",
|
|
56
|
+
"pandas",
|
|
57
|
+
"matplotlib>=3.9", # cosine-similarity heat-map
|
|
58
|
+
"pycountry>=23.12", # ISO language names for pretty dropdown labels
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
[project.optional-dependencies]
|
|
62
|
+
examples = [
|
|
63
|
+
"flask",
|
|
64
|
+
"streamlit",
|
|
65
|
+
"jupyterlab",
|
|
66
|
+
]
|
|
67
|
+
winlid = []
|
|
68
|
+
corpus = [
|
|
69
|
+
"datasets>=3.0",
|
|
70
|
+
"pyarrow>=14.0",
|
|
71
|
+
"requests>=2.0",
|
|
72
|
+
"zstandard>=0.23",
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
# Development tools
|
|
76
|
+
dev = [
|
|
77
|
+
"ruff>=0.2.0", # Fast linter
|
|
78
|
+
"mypy>=1.0", # Type checker
|
|
79
|
+
"pytest>=8.0", # Testing framework
|
|
80
|
+
"build>=1.0", # Package builder
|
|
81
|
+
"twine>=4.0", # Package uploader
|
|
82
|
+
"make>=0.1.6", # Make command for Windows
|
|
83
|
+
"types-requests>=2.31", # Type stubs for requests
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
[project.scripts]
|
|
87
|
+
turkic-translit = "turkic_translit.cli:main"
|
|
88
|
+
turkic-pyicu-install = "turkic_translit.cli.pyicu_install:main"
|
|
89
|
+
turkic-filter-russian = "turkic_translit.cli.filter_russian:main"
|
|
90
|
+
turkic-download-corpus = "turkic_translit.cli.download_corpus:cli"
|
|
91
|
+
turkic-build-spm = "turkic_translit.cli.build_spm:main"
|
|
92
|
+
turkic-leven = "turkic_translit.cli.run_leven:main"
|
|
93
|
+
turkic-web = "turkic_translit.web.web_demo:main"
|
|
94
|
+
turkic-train-lm = "turkic_translit.cli.train_lm:cli"
|
|
95
|
+
turkic-eval-lm = "turkic_translit.cli.eval_lm:cli"
|
|
96
|
+
turkic-train-spm = "turkic_translit.cli.train_spm:main"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
[tool.setuptools.packages]
|
|
100
|
+
find = { where = ["src"] }
|
|
101
|
+
|
|
102
|
+
[tool.setuptools]
|
|
103
|
+
include-package-data = true
|
|
104
|
+
package-dir = {"" = "src"}
|
|
105
|
+
|
|
106
|
+
[tool.setuptools.package-data]
|
|
107
|
+
"turkic_translit" = ["rules/*.rules"]
|
|
108
|
+
"turkic_translit.cli" = ["corpora.yaml"]
|
|
109
|
+
|
|
110
|
+
[tool.ruff]
|
|
111
|
+
line-length = 88
|
|
112
|
+
target-version = "py39"
|
|
113
|
+
src = ["src", "tests", "examples"]
|
|
114
|
+
|
|
115
|
+
[tool.ruff.lint]
|
|
116
|
+
select = [
|
|
117
|
+
"E", # pycodestyle errors
|
|
118
|
+
"F", # pyflakes
|
|
119
|
+
"I", # isort
|
|
120
|
+
"UP", # pyupgrade
|
|
121
|
+
"N", # pep8-naming
|
|
122
|
+
"B", # flake8-bugbear
|
|
123
|
+
"C4", # flake8-comprehensions
|
|
124
|
+
"SIM", # flake8-simplify
|
|
125
|
+
"PT", # flake8-pytest-style
|
|
126
|
+
"RET", # flake8-return
|
|
127
|
+
"PIE", # flake8-pie
|
|
128
|
+
]
|
|
129
|
+
ignore = [
|
|
130
|
+
"E501" # line too long (handled by formatter)
|
|
131
|
+
]
|
|
132
|
+
|
|
133
|
+
[tool.ruff.lint.isort]
|
|
134
|
+
known-first-party = ["turkic_translit"]
|
|
135
|
+
|
|
136
|
+
[tool.ruff.lint.per-file-ignores]
|
|
137
|
+
"__init__.py" = ["F401"] # unused imports
|
|
138
|
+
"tests/*" = ["E731"] # do not assign a lambda expression
|
|
139
|
+
"examples/*" = ["E402"] # module level import not at top of file
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import platform
|
|
2
|
+
import sys
|
|
3
|
+
from importlib.metadata import version
|
|
4
|
+
|
|
5
|
+
# Public sub-packages (optional heavy deps)
|
|
6
|
+
try:
|
|
7
|
+
from . import lm as lm # noqa: F401
|
|
8
|
+
except Exception: # pragma: no cover – missing optional deps
|
|
9
|
+
lm = None # type: ignore
|
|
10
|
+
|
|
11
|
+
from . import patches as _patches # noqa: F401
|
|
12
|
+
from .core import to_ipa, to_latin
|
|
13
|
+
from .logging_config import setup as _log_setup
|
|
14
|
+
from .web.web_utils import (
|
|
15
|
+
direct_transliterate,
|
|
16
|
+
mask_russian,
|
|
17
|
+
median_levenshtein,
|
|
18
|
+
pipeline_transliterate,
|
|
19
|
+
token_table_markdown,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
_log_setup()
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"to_latin",
|
|
26
|
+
"to_ipa",
|
|
27
|
+
"direct_transliterate",
|
|
28
|
+
"pipeline_transliterate",
|
|
29
|
+
"token_table_markdown",
|
|
30
|
+
"mask_russian",
|
|
31
|
+
"median_levenshtein",
|
|
32
|
+
"lang_filter",
|
|
33
|
+
*(["lm"] if lm is not None else []),
|
|
34
|
+
]
|
|
35
|
+
# Retrieve version from package metadata. Package is published as "turkic-translit" on PyPI.
|
|
36
|
+
__version__ = version("turkic-translit")
|
|
37
|
+
|
|
38
|
+
# Warn Windows users on Python >=3.12 if PyICU is not importable
|
|
39
|
+
if platform.system() == "Windows" and sys.version_info >= (3, 12):
|
|
40
|
+
try:
|
|
41
|
+
import PyICU # noqa: F401
|
|
42
|
+
except ImportError:
|
|
43
|
+
import sys as _sys
|
|
44
|
+
|
|
45
|
+
_sys.stderr.write(
|
|
46
|
+
"[turkic-transliterate] ERROR: PyICU is not installed and cannot be built automatically on Windows for Python 3.12+!\n"
|
|
47
|
+
"To use this package, please create a virtual environment with Python 3.11 and install as follows:\n\n"
|
|
48
|
+
" py -3.11 -m venv turkic311\n"
|
|
49
|
+
" turkic311\\Scripts\\activate\n"
|
|
50
|
+
" pip install turkic-transliterate\n"
|
|
51
|
+
" turkic-pyicu-install\n\n"
|
|
52
|
+
"See the README for more details.\n"
|
|
53
|
+
)
|