alifbo 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.
@@ -0,0 +1,13 @@
1
+ node_modules/
2
+ dist/
3
+ coverage/
4
+ .DS_Store
5
+ _site/
6
+ .claude/
7
+ python/.venv/
8
+ python/dist/
9
+ python/build/
10
+ *.egg-info/
11
+ __pycache__/
12
+ .pytest_cache/
13
+ .ruff_cache/
alifbo-0.2.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 alifbo contributors
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.
alifbo-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,114 @@
1
+ Metadata-Version: 2.5
2
+ Name: alifbo
3
+ Version: 0.2.0
4
+ Summary: Uzbek transliteration between Cyrillic, old Latin, and the 2026 Latin alphabet
5
+ Project-URL: Homepage, https://github.com/azakapro/alifbo
6
+ Project-URL: Repository, https://github.com/azakapro/alifbo
7
+ Project-URL: Issues, https://github.com/azakapro/alifbo/issues
8
+ Project-URL: Changelog, https://github.com/azakapro/alifbo/blob/main/CHANGELOG.md
9
+ Author: azakapro
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: cyrillic,latin,normalization,transliteration,unicode,uzbek
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Topic :: Text Processing :: Linguistic
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+
23
+ # alifbo for Python
24
+
25
+ Python port of [`alifbo`](https://github.com/azakapro/alifbo): Uzbek transliteration between Cyrillic, the previous Latin alphabet, and the Latin alphabet approved by Uzbekistan's Senate on 10 September 2026. The amending law still awaits the president's signature and is not yet in force.
26
+
27
+ The port has zero runtime dependencies, supports Python 3.9+, ships type hints (`py.typed`), and is tested against a fixture of more than 13,000 cases generated from the TypeScript build to produce identical output.
28
+
29
+ ## Install
30
+
31
+ ```sh
32
+ pip install alifbo
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ ```python
38
+ from alifbo import fold_search_key, from_cyrillic, to_cyrillic, to_new_latin, to_old_latin
39
+
40
+ to_new_latin("O'zbekiston shaharlari")
41
+ # ConversionResult(text='Özbekiston şaharlari', warnings=())
42
+
43
+ to_old_latin("Özbekiston şaharlari").text
44
+ # 'Oʻzbekiston shaharlari'
45
+
46
+ result = from_cyrillic("Елена")
47
+ result.text
48
+ # 'Yelena'
49
+ result.warnings[0]
50
+ # Warning(index=0, length=1, rule='cyrillic.e.positional',
51
+ # message='Cyrillic е can represent e or ye; a positional rule was applied.',
52
+ # alternatives=('e', 'ye'))
53
+
54
+ to_cyrillic("Şavkat").text
55
+ # 'Шавкат'
56
+
57
+ fold_search_key("Шавкат") == fold_search_key("Shavkat")
58
+ # True
59
+
60
+ to_new_latin("MyShop shahar", protected_terms=["MyShop"]).text
61
+ # 'MyShop şahar'
62
+ ```
63
+
64
+ ## API
65
+
66
+ Conversion functions return a frozen `ConversionResult(text, warnings)`, where `warnings` is a tuple of frozen `Warning(index, length, rule, message, alternatives)` objects:
67
+
68
+ - `to_new_latin(text, **options)`: previous Latin to new Latin.
69
+ - `to_old_latin(text, **options)`: new Latin to previous Latin.
70
+ - `from_cyrillic(text, **options)`: Cyrillic to new Latin, with ambiguity warnings.
71
+ - `to_cyrillic(text, **options)`: new Latin to Cyrillic, with ambiguity warnings.
72
+
73
+ Their keyword-only options mirror the TypeScript `ConversionOptions`:
74
+
75
+ | Python | TypeScript | Default |
76
+ | ----------------- | ---------------- | ------- |
77
+ | `protect_spans` | `protectSpans` | `True` |
78
+ | `protected_terms` | `protectedTerms` | `None` |
79
+ | `exceptions` | `exceptions` | `None` |
80
+ | `ng_as_digraph` | `ngAsDigraph` | `True` |
81
+
82
+ The other functions take only `text`:
83
+
84
+ - `fold_search_key(text)`: canonical new-Latin, NFC, locale-independent lowercase key.
85
+ - `fold_search_key_loose(text)`: also strips diacritics. It can merge distinct words, so never use it as a unique key.
86
+ - `normalize_apostrophes(text)`: folds apostrophe-like characters to U+02BB after `o`/`g` and to U+02BC elsewhere.
87
+ - `normalize_confusables(text)`: NFC-normalizes text and folds known confusables such as U+0219 to U+015F.
88
+ - `detect_alphabet(text)`: returns `AlphabetDetection(alphabet, confidence)`. `alphabet` is one of `'cyrillic'`, `'old-latin'`, `'new-latin'`, `'mixed'`, or `'unknown'`.
89
+
90
+ ## Differences from the TypeScript package
91
+
92
+ - **Warning offsets are Python string indexes (code points).** The TypeScript package reports UTF-16 code-unit offsets. The two are equal unless the text contains characters outside the Basic Multilingual Plane, such as emoji. For example, `from_cyrillic("😀 Елена")` reports warnings at indexes `[2, 4]` in Python and `[3, 5]` in JavaScript. Offsets point into the text you passed in, before NFC normalization, exceptions, or (for `to_cyrillic`) the old-to-new Latin pre-pass, just as they do in TypeScript.
93
+ - Names are snake_case, options are keyword arguments, and results are immutable dataclasses with tuples instead of arrays.
94
+ - An empty string used as an `exceptions` key is ignored. The TypeScript package can loop forever on one.
95
+ - Unicode character properties come from the running Python's `unicodedata` module. Characters added in newer Unicode versions may be classified differently than they are by your JavaScript engine.
96
+
97
+ Casing never uses Python's built-in string case methods. It uses the same explicit Latin and Cyrillic tables as the TypeScript package, so the Turkish `İ`/`ı` problem cannot occur.
98
+
99
+ ## Rules
100
+
101
+ The conversion pipeline, apostrophe handling, the `sʼh` boundary, Cyrillic ambiguity rules, and the open `ng` question are documented in the [main README](https://github.com/azakapro/alifbo#readme).
102
+
103
+ ## Development
104
+
105
+ From the repository root:
106
+
107
+ ```sh
108
+ npm ci && npm run build && node scripts/gen-python-parity.mjs
109
+ cd python
110
+ uv run --with pytest pytest
111
+ uv run --with ruff ruff check . && uv run --with ruff ruff format --check .
112
+ ```
113
+
114
+ Released under the MIT License.
alifbo-0.2.0/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # alifbo for Python
2
+
3
+ Python port of [`alifbo`](https://github.com/azakapro/alifbo): Uzbek transliteration between Cyrillic, the previous Latin alphabet, and the Latin alphabet approved by Uzbekistan's Senate on 10 September 2026. The amending law still awaits the president's signature and is not yet in force.
4
+
5
+ The port has zero runtime dependencies, supports Python 3.9+, ships type hints (`py.typed`), and is tested against a fixture of more than 13,000 cases generated from the TypeScript build to produce identical output.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ pip install alifbo
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```python
16
+ from alifbo import fold_search_key, from_cyrillic, to_cyrillic, to_new_latin, to_old_latin
17
+
18
+ to_new_latin("O'zbekiston shaharlari")
19
+ # ConversionResult(text='Özbekiston şaharlari', warnings=())
20
+
21
+ to_old_latin("Özbekiston şaharlari").text
22
+ # 'Oʻzbekiston shaharlari'
23
+
24
+ result = from_cyrillic("Елена")
25
+ result.text
26
+ # 'Yelena'
27
+ result.warnings[0]
28
+ # Warning(index=0, length=1, rule='cyrillic.e.positional',
29
+ # message='Cyrillic е can represent e or ye; a positional rule was applied.',
30
+ # alternatives=('e', 'ye'))
31
+
32
+ to_cyrillic("Şavkat").text
33
+ # 'Шавкат'
34
+
35
+ fold_search_key("Шавкат") == fold_search_key("Shavkat")
36
+ # True
37
+
38
+ to_new_latin("MyShop shahar", protected_terms=["MyShop"]).text
39
+ # 'MyShop şahar'
40
+ ```
41
+
42
+ ## API
43
+
44
+ Conversion functions return a frozen `ConversionResult(text, warnings)`, where `warnings` is a tuple of frozen `Warning(index, length, rule, message, alternatives)` objects:
45
+
46
+ - `to_new_latin(text, **options)`: previous Latin to new Latin.
47
+ - `to_old_latin(text, **options)`: new Latin to previous Latin.
48
+ - `from_cyrillic(text, **options)`: Cyrillic to new Latin, with ambiguity warnings.
49
+ - `to_cyrillic(text, **options)`: new Latin to Cyrillic, with ambiguity warnings.
50
+
51
+ Their keyword-only options mirror the TypeScript `ConversionOptions`:
52
+
53
+ | Python | TypeScript | Default |
54
+ | ----------------- | ---------------- | ------- |
55
+ | `protect_spans` | `protectSpans` | `True` |
56
+ | `protected_terms` | `protectedTerms` | `None` |
57
+ | `exceptions` | `exceptions` | `None` |
58
+ | `ng_as_digraph` | `ngAsDigraph` | `True` |
59
+
60
+ The other functions take only `text`:
61
+
62
+ - `fold_search_key(text)`: canonical new-Latin, NFC, locale-independent lowercase key.
63
+ - `fold_search_key_loose(text)`: also strips diacritics. It can merge distinct words, so never use it as a unique key.
64
+ - `normalize_apostrophes(text)`: folds apostrophe-like characters to U+02BB after `o`/`g` and to U+02BC elsewhere.
65
+ - `normalize_confusables(text)`: NFC-normalizes text and folds known confusables such as U+0219 to U+015F.
66
+ - `detect_alphabet(text)`: returns `AlphabetDetection(alphabet, confidence)`. `alphabet` is one of `'cyrillic'`, `'old-latin'`, `'new-latin'`, `'mixed'`, or `'unknown'`.
67
+
68
+ ## Differences from the TypeScript package
69
+
70
+ - **Warning offsets are Python string indexes (code points).** The TypeScript package reports UTF-16 code-unit offsets. The two are equal unless the text contains characters outside the Basic Multilingual Plane, such as emoji. For example, `from_cyrillic("😀 Елена")` reports warnings at indexes `[2, 4]` in Python and `[3, 5]` in JavaScript. Offsets point into the text you passed in, before NFC normalization, exceptions, or (for `to_cyrillic`) the old-to-new Latin pre-pass, just as they do in TypeScript.
71
+ - Names are snake_case, options are keyword arguments, and results are immutable dataclasses with tuples instead of arrays.
72
+ - An empty string used as an `exceptions` key is ignored. The TypeScript package can loop forever on one.
73
+ - Unicode character properties come from the running Python's `unicodedata` module. Characters added in newer Unicode versions may be classified differently than they are by your JavaScript engine.
74
+
75
+ Casing never uses Python's built-in string case methods. It uses the same explicit Latin and Cyrillic tables as the TypeScript package, so the Turkish `İ`/`ı` problem cannot occur.
76
+
77
+ ## Rules
78
+
79
+ The conversion pipeline, apostrophe handling, the `sʼh` boundary, Cyrillic ambiguity rules, and the open `ng` question are documented in the [main README](https://github.com/azakapro/alifbo#readme).
80
+
81
+ ## Development
82
+
83
+ From the repository root:
84
+
85
+ ```sh
86
+ npm ci && npm run build && node scripts/gen-python-parity.mjs
87
+ cd python
88
+ uv run --with pytest pytest
89
+ uv run --with ruff ruff check . && uv run --with ruff ruff format --check .
90
+ ```
91
+
92
+ Released under the MIT License.
@@ -0,0 +1,50 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "alifbo"
7
+ version = "0.2.0"
8
+ description = "Uzbek transliteration between Cyrillic, old Latin, and the 2026 Latin alphabet"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "azakapro" }]
14
+ keywords = ["uzbek", "transliteration", "cyrillic", "latin", "unicode", "normalization"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3 :: Only",
21
+ "Topic :: Text Processing :: Linguistic",
22
+ "Typing :: Typed",
23
+ ]
24
+ dependencies = []
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/azakapro/alifbo"
28
+ Repository = "https://github.com/azakapro/alifbo"
29
+ Issues = "https://github.com/azakapro/alifbo/issues"
30
+ Changelog = "https://github.com/azakapro/alifbo/blob/main/CHANGELOG.md"
31
+
32
+ [tool.hatch.build.targets.wheel]
33
+ packages = ["src/alifbo"]
34
+
35
+ [tool.hatch.build.targets.sdist]
36
+ include = ["src/alifbo", "README.md", "LICENSE", "pyproject.toml"]
37
+
38
+ [tool.pytest.ini_options]
39
+ testpaths = ["tests"]
40
+ pythonpath = ["src"]
41
+
42
+ [tool.ruff]
43
+ target-version = "py39"
44
+ line-length = 100
45
+ src = ["src", "tests"]
46
+
47
+ [tool.ruff.lint]
48
+ select = ["E", "F", "W", "I", "B", "UP", "SIM", "RUF"]
49
+ # Keep typing.Optional/Tuple spellings that read naturally on Python 3.9.
50
+ ignore = ["UP006", "UP007", "UP035", "UP045", "RUF001", "RUF002", "RUF003"]
@@ -0,0 +1,29 @@
1
+ """Uzbek transliteration between Cyrillic, old Latin, and the 2026 Latin alphabet."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from .cyrillic import from_cyrillic, to_cyrillic
6
+ from .detect import detect_alphabet
7
+ from .latin import to_new_latin, to_old_latin
8
+ from .normalize import normalize_apostrophes, normalize_confusables
9
+ from .search import fold_search_key, fold_search_key_loose
10
+ from .types import Alphabet, AlphabetDetection, ConversionResult, Warning
11
+
12
+ __version__ = "0.2.0"
13
+
14
+ __all__ = [
15
+ "Alphabet",
16
+ "AlphabetDetection",
17
+ "ConversionResult",
18
+ "Warning",
19
+ "__version__",
20
+ "detect_alphabet",
21
+ "fold_search_key",
22
+ "fold_search_key_loose",
23
+ "from_cyrillic",
24
+ "normalize_apostrophes",
25
+ "normalize_confusables",
26
+ "to_cyrillic",
27
+ "to_new_latin",
28
+ "to_old_latin",
29
+ ]
@@ -0,0 +1,107 @@
1
+ """Explicit, locale-independent case tables (mirrors ``src/case.ts``).
2
+
3
+ Python's built-in string case methods are never used on user text: the tables
4
+ below are the only case mapping this package performs.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ _CASE_PAIRS = (
10
+ ("a", "A"),
11
+ ("b", "B"),
12
+ ("c", "C"),
13
+ ("d", "D"),
14
+ ("e", "E"),
15
+ ("f", "F"),
16
+ ("g", "G"),
17
+ ("h", "H"),
18
+ ("i", "I"),
19
+ ("j", "J"),
20
+ ("k", "K"),
21
+ ("l", "L"),
22
+ ("m", "M"),
23
+ ("n", "N"),
24
+ ("o", "O"),
25
+ ("p", "P"),
26
+ ("q", "Q"),
27
+ ("r", "R"),
28
+ ("s", "S"),
29
+ ("t", "T"),
30
+ ("u", "U"),
31
+ ("v", "V"),
32
+ ("w", "W"),
33
+ ("x", "X"),
34
+ ("y", "Y"),
35
+ ("z", "Z"),
36
+ ("ö", "Ö"),
37
+ ("ğ", "Ğ"),
38
+ ("ş", "Ş"),
39
+ ("ç", "Ç"),
40
+ ("ș", "Ș"),
41
+ ("а", "А"),
42
+ ("б", "Б"),
43
+ ("в", "В"),
44
+ ("г", "Г"),
45
+ ("д", "Д"),
46
+ ("е", "Е"),
47
+ ("ё", "Ё"),
48
+ ("ж", "Ж"),
49
+ ("з", "З"),
50
+ ("и", "И"),
51
+ ("й", "Й"),
52
+ ("к", "К"),
53
+ ("л", "Л"),
54
+ ("м", "М"),
55
+ ("н", "Н"),
56
+ ("о", "О"),
57
+ ("п", "П"),
58
+ ("р", "Р"),
59
+ ("с", "С"),
60
+ ("т", "Т"),
61
+ ("у", "У"),
62
+ ("ф", "Ф"),
63
+ ("х", "Х"),
64
+ ("ц", "Ц"),
65
+ ("ч", "Ч"),
66
+ ("ш", "Ш"),
67
+ ("щ", "Щ"),
68
+ ("ъ", "Ъ"),
69
+ ("ы", "Ы"),
70
+ ("ь", "Ь"),
71
+ ("э", "Э"),
72
+ ("ю", "Ю"),
73
+ ("я", "Я"),
74
+ ("ў", "Ў"),
75
+ ("қ", "Қ"),
76
+ ("ғ", "Ғ"),
77
+ ("ҳ", "Ҳ"),
78
+ )
79
+
80
+ _LOWER_TO_UPPER = dict(_CASE_PAIRS)
81
+ _UPPER_TO_LOWER = {upper: lower for lower, upper in _CASE_PAIRS}
82
+
83
+
84
+ def lower_char(character: str) -> str:
85
+ return _UPPER_TO_LOWER.get(character, character)
86
+
87
+
88
+ def upper_char(character: str) -> str:
89
+ return _LOWER_TO_UPPER.get(character, character)
90
+
91
+
92
+ def lower_text(text: str) -> str:
93
+ return "".join(_UPPER_TO_LOWER.get(character, character) for character in text)
94
+
95
+
96
+ def upper_text(text: str) -> str:
97
+ return "".join(_LOWER_TO_UPPER.get(character, character) for character in text)
98
+
99
+
100
+ def is_upper(character: str) -> bool:
101
+ return character in _UPPER_TO_LOWER
102
+
103
+
104
+ def first_case(source: str, lower_output: str) -> str:
105
+ if not is_upper(source) or len(lower_output) == 0:
106
+ return lower_output
107
+ return upper_char(lower_output[0]) + lower_output[1:]