trkit-aea 0.5.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.
- trkit_aea-0.5.0/.gitignore +21 -0
- trkit_aea-0.5.0/PKG-INFO +110 -0
- trkit_aea-0.5.0/README.md +83 -0
- trkit_aea-0.5.0/conformance/run.py +214 -0
- trkit_aea-0.5.0/pyproject.toml +59 -0
- trkit_aea-0.5.0/src/trkit/__init__.py +81 -0
- trkit_aea-0.5.0/src/trkit/_case.py +101 -0
- trkit_aea-0.5.0/src/trkit/_data.py +117 -0
- trkit_aea-0.5.0/src/trkit/_deasciify.py +92 -0
- trkit_aea-0.5.0/src/trkit/_normalize.py +315 -0
- trkit_aea-0.5.0/src/trkit/_numbers.py +86 -0
- trkit_aea-0.5.0/src/trkit/_search.py +91 -0
- trkit_aea-0.5.0/src/trkit/_snowball/COPYING +29 -0
- trkit_aea-0.5.0/src/trkit/_snowball/__init__.py +0 -0
- trkit_aea-0.5.0/src/trkit/_snowball/among.py +12 -0
- trkit_aea-0.5.0/src/trkit/_snowball/basestemmer.py +279 -0
- trkit_aea-0.5.0/src/trkit/_snowball/turkish_stemmer.py +1457 -0
- trkit_aea-0.5.0/src/trkit/_stem.py +22 -0
- trkit_aea-0.5.0/src/trkit/_suffix.py +301 -0
- trkit_aea-0.5.0/src/trkit/_tokenize.py +60 -0
- trkit_aea-0.5.0/src/trkit/_unicode.py +37 -0
- trkit_aea-0.5.0/src/trkit/data/MANIFEST.json +27 -0
- trkit_aea-0.5.0/src/trkit/data/VERSION +3 -0
- trkit_aea-0.5.0/src/trkit/data/abbreviations.toml +16 -0
- trkit_aea-0.5.0/src/trkit/data/exceptions.toml +190 -0
- trkit_aea-0.5.0/src/trkit/data/json/abbreviations.json +14 -0
- trkit_aea-0.5.0/src/trkit/data/json/deasciify.json +1 -0
- trkit_aea-0.5.0/src/trkit/data/json/exceptions.json +1226 -0
- trkit_aea-0.5.0/src/trkit/data/json/letters.json +38 -0
- trkit_aea-0.5.0/src/trkit/data/json/stopwords.tr.json +174 -0
- trkit_aea-0.5.0/src/trkit/data/letters.toml +38 -0
- trkit_aea-0.5.0/src/trkit/data/stopwords.tr.toml +35 -0
- trkit_aea-0.5.0/src/trkit/data/unicode/nfc.json +1 -0
- trkit_aea-0.5.0/src/trkit/data/vectors/case.json +59 -0
- trkit_aea-0.5.0/src/trkit/data/vectors/deasciify.json +170 -0
- trkit_aea-0.5.0/src/trkit/data/vectors/mojibake.json +22 -0
- trkit_aea-0.5.0/src/trkit/data/vectors/normalize.json +43 -0
- trkit_aea-0.5.0/src/trkit/data/vectors/numbers.json +36 -0
- trkit_aea-0.5.0/src/trkit/data/vectors/search.json +22 -0
- trkit_aea-0.5.0/src/trkit/data/vectors/slug.json +26 -0
- trkit_aea-0.5.0/src/trkit/data/vectors/stem.json +8736 -0
- trkit_aea-0.5.0/src/trkit/data/vectors/suffix.json +1043 -0
- trkit_aea-0.5.0/src/trkit/data/vectors/tokenize.json +25 -0
- trkit_aea-0.5.0/src/trkit/py.typed +0 -0
- trkit_aea-0.5.0/tests/test_case.py +114 -0
- trkit_aea-0.5.0/tests/test_conformance.py +46 -0
- trkit_aea-0.5.0/tests/test_data_sync.py +116 -0
- trkit_aea-0.5.0/tests/test_normalize.py +139 -0
- trkit_aea-0.5.0/tests/test_properties.py +124 -0
- trkit_aea-0.5.0/tests/test_search.py +84 -0
- trkit_aea-0.5.0/tests/test_suffix.py +114 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
*.py[cod]
|
|
3
|
+
.eggs/
|
|
4
|
+
build/
|
|
5
|
+
.coverage
|
|
6
|
+
htmlcov/
|
|
7
|
+
|
|
8
|
+
# Node (JS port)
|
|
9
|
+
|
|
10
|
+
# Go
|
|
11
|
+
*.test
|
|
12
|
+
|
|
13
|
+
# Java
|
|
14
|
+
|
|
15
|
+
# PHP
|
|
16
|
+
vendor/
|
|
17
|
+
|
|
18
|
+
# Benchmark / corpus scratch (never committed, see docs/PLAN.md 10.1)
|
|
19
|
+
bench/_cache/
|
|
20
|
+
*.parquet
|
|
21
|
+
# Rust
|
trkit_aea-0.5.0/PKG-INFO
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: trkit-aea
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: Turkish text hygiene for programmers: correct casing, normalization, slugging and search keys. Zero runtime dependencies.
|
|
5
|
+
Project-URL: Homepage, https://github.com/akiciemir/trkit
|
|
6
|
+
Project-URL: Repository, https://github.com/akiciemir/trkit
|
|
7
|
+
Project-URL: Issues, https://github.com/akiciemir/trkit/issues
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
Keywords: case,lowercase,normalize,search,slug,turkce,turkish,unicode
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Natural Language :: Turkish
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: hypothesis>=6; extra == 'dev'
|
|
23
|
+
Requires-Dist: mypy>=1.11; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
25
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# trkit (Python port)
|
|
29
|
+
|
|
30
|
+
Turkish text hygiene for programmers — correct casing, normalization and
|
|
31
|
+
slugs, zero runtime dependencies, Python ≥ 3.11.
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import trkit
|
|
35
|
+
|
|
36
|
+
trkit.lower("ISPARTA") # 'ısparta' (str.lower -> 'isparta')
|
|
37
|
+
trkit.upper("i") # 'İ'
|
|
38
|
+
trkit.title("ankara'nın kitapları") # "Ankara'nın Kitapları"
|
|
39
|
+
trkit.casefold("IŞIK") # 'isik'
|
|
40
|
+
trkit.slug("Çığlık Şöleni 2026!") # 'ciglik-soleni-2026'
|
|
41
|
+
trkit.fix_mojibake("çiçlük") # 'çiçlük'
|
|
42
|
+
trkit.suffix("kitap", "acc") # 'kitabı'
|
|
43
|
+
trkit.suffix("Ankara", "abl") # "Ankara'dan"
|
|
44
|
+
trkit.numwords(45) # 'kırk beş'
|
|
45
|
+
trkit.search_key("IŞIK") # 'isik'
|
|
46
|
+
trkit.search_tokens("İstanbul'da") # [['İstanbul'da', "istanbul'da", 'istan']]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Modules: `case`, `normalize` (fold/slug/mojibake), `suffix` + `numwords`,
|
|
50
|
+
`search` (`search_key`, `stem_f5`, `search_tokens`, `meilisearch_preset`).
|
|
51
|
+
|
|
52
|
+
Install from this monorepo:
|
|
53
|
+
|
|
54
|
+
```powershell
|
|
55
|
+
pip install -e packages/python
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Run the tests and the shared vector suite:
|
|
59
|
+
|
|
60
|
+
```powershell
|
|
61
|
+
$env:PYTHONPATH = "packages\python\src"
|
|
62
|
+
python -m unittest discover -s packages\python\tests
|
|
63
|
+
python packages\python\conformance\run.py
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The specification is [`docs/spec/`](../../docs/spec/); the project README is
|
|
67
|
+
[the repository root README](../../README.md). Status of every port: there.
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
# Türkçe
|
|
72
|
+
|
|
73
|
+
Programcılar için Türkçe metin hijyeni — doğru büyük/küçük harf, normalizasyon
|
|
74
|
+
ve slug üretimi; sıfır çalışma zamanı bağımlılığı, Python ≥ 3.11.
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
import trkit
|
|
78
|
+
|
|
79
|
+
trkit.lower("ISPARTA") # 'ısparta' (str.lower -> 'isparta')
|
|
80
|
+
trkit.upper("i") # 'İ'
|
|
81
|
+
trkit.title("ankara'nın kitapları") # "Ankara'nın Kitapları"
|
|
82
|
+
trkit.casefold("IŞIK") # 'isik'
|
|
83
|
+
trkit.slug("Çığlık Şöleni 2026!") # 'ciglik-soleni-2026'
|
|
84
|
+
trkit.fix_mojibake("çiçlük") # 'çiçlük'
|
|
85
|
+
trkit.suffix("kitap", "acc") # 'kitabı'
|
|
86
|
+
trkit.suffix("Ankara", "abl") # "Ankara'dan"
|
|
87
|
+
trkit.numwords(45) # 'kırk beş'
|
|
88
|
+
trkit.search_key("IŞIK") # 'isik'
|
|
89
|
+
trkit.search_tokens("İstanbul'da") # [['İstanbul'da', "istanbul'da", 'istan']]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Modüller: `case`, `normalize` (fold/slug/mojibake), `suffix` + `numwords`,
|
|
93
|
+
`search` (`search_key`, `stem_f5`, `search_tokens`, `meilisearch_preset`).
|
|
94
|
+
|
|
95
|
+
Bu monorepo'dan kurulum:
|
|
96
|
+
|
|
97
|
+
```powershell
|
|
98
|
+
pip install -e packages/python
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Testleri ve ortak vektör kümesini çalıştırın:
|
|
102
|
+
|
|
103
|
+
```powershell
|
|
104
|
+
$env:PYTHONPATH = "packages\python\src"
|
|
105
|
+
python -m unittest discover -s packages\python\tests
|
|
106
|
+
python packages\python\conformance\run.py
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Spec [`docs/spec/`](../../docs/spec/); proje README'si
|
|
110
|
+
[depo kökü README](../../README.md). Tüm portların durumu: orada.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# trkit (Python port)
|
|
2
|
+
|
|
3
|
+
Turkish text hygiene for programmers — correct casing, normalization and
|
|
4
|
+
slugs, zero runtime dependencies, Python ≥ 3.11.
|
|
5
|
+
|
|
6
|
+
```python
|
|
7
|
+
import trkit
|
|
8
|
+
|
|
9
|
+
trkit.lower("ISPARTA") # 'ısparta' (str.lower -> 'isparta')
|
|
10
|
+
trkit.upper("i") # 'İ'
|
|
11
|
+
trkit.title("ankara'nın kitapları") # "Ankara'nın Kitapları"
|
|
12
|
+
trkit.casefold("IŞIK") # 'isik'
|
|
13
|
+
trkit.slug("Çığlık Şöleni 2026!") # 'ciglik-soleni-2026'
|
|
14
|
+
trkit.fix_mojibake("çiçlük") # 'çiçlük'
|
|
15
|
+
trkit.suffix("kitap", "acc") # 'kitabı'
|
|
16
|
+
trkit.suffix("Ankara", "abl") # "Ankara'dan"
|
|
17
|
+
trkit.numwords(45) # 'kırk beş'
|
|
18
|
+
trkit.search_key("IŞIK") # 'isik'
|
|
19
|
+
trkit.search_tokens("İstanbul'da") # [['İstanbul'da', "istanbul'da", 'istan']]
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Modules: `case`, `normalize` (fold/slug/mojibake), `suffix` + `numwords`,
|
|
23
|
+
`search` (`search_key`, `stem_f5`, `search_tokens`, `meilisearch_preset`).
|
|
24
|
+
|
|
25
|
+
Install from this monorepo:
|
|
26
|
+
|
|
27
|
+
```powershell
|
|
28
|
+
pip install -e packages/python
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Run the tests and the shared vector suite:
|
|
32
|
+
|
|
33
|
+
```powershell
|
|
34
|
+
$env:PYTHONPATH = "packages\python\src"
|
|
35
|
+
python -m unittest discover -s packages\python\tests
|
|
36
|
+
python packages\python\conformance\run.py
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The specification is [`docs/spec/`](../../docs/spec/); the project README is
|
|
40
|
+
[the repository root README](../../README.md). Status of every port: there.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
# Türkçe
|
|
45
|
+
|
|
46
|
+
Programcılar için Türkçe metin hijyeni — doğru büyük/küçük harf, normalizasyon
|
|
47
|
+
ve slug üretimi; sıfır çalışma zamanı bağımlılığı, Python ≥ 3.11.
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
import trkit
|
|
51
|
+
|
|
52
|
+
trkit.lower("ISPARTA") # 'ısparta' (str.lower -> 'isparta')
|
|
53
|
+
trkit.upper("i") # 'İ'
|
|
54
|
+
trkit.title("ankara'nın kitapları") # "Ankara'nın Kitapları"
|
|
55
|
+
trkit.casefold("IŞIK") # 'isik'
|
|
56
|
+
trkit.slug("Çığlık Şöleni 2026!") # 'ciglik-soleni-2026'
|
|
57
|
+
trkit.fix_mojibake("çiçlük") # 'çiçlük'
|
|
58
|
+
trkit.suffix("kitap", "acc") # 'kitabı'
|
|
59
|
+
trkit.suffix("Ankara", "abl") # "Ankara'dan"
|
|
60
|
+
trkit.numwords(45) # 'kırk beş'
|
|
61
|
+
trkit.search_key("IŞIK") # 'isik'
|
|
62
|
+
trkit.search_tokens("İstanbul'da") # [['İstanbul'da', "istanbul'da", 'istan']]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Modüller: `case`, `normalize` (fold/slug/mojibake), `suffix` + `numwords`,
|
|
66
|
+
`search` (`search_key`, `stem_f5`, `search_tokens`, `meilisearch_preset`).
|
|
67
|
+
|
|
68
|
+
Bu monorepo'dan kurulum:
|
|
69
|
+
|
|
70
|
+
```powershell
|
|
71
|
+
pip install -e packages/python
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Testleri ve ortak vektör kümesini çalıştırın:
|
|
75
|
+
|
|
76
|
+
```powershell
|
|
77
|
+
$env:PYTHONPATH = "packages\python\src"
|
|
78
|
+
python -m unittest discover -s packages\python\tests
|
|
79
|
+
python packages\python\conformance\run.py
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Spec [`docs/spec/`](../../docs/spec/); proje README'si
|
|
83
|
+
[depo kökü README](../../README.md). Tüm portların durumu: orada.
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""trkit conformance runner (Python port).
|
|
3
|
+
|
|
4
|
+
python packages/python/conformance/run.py [--data data] [--module case]
|
|
5
|
+
[--json] [--quiet]
|
|
6
|
+
|
|
7
|
+
Exit codes (spec 06 section 3):
|
|
8
|
+
0 every record matched (or was an expected failure)
|
|
9
|
+
1 at least one real mismatch
|
|
10
|
+
2 a vector file could not be read / schema error / version mismatch
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import argparse
|
|
16
|
+
import json
|
|
17
|
+
import sys
|
|
18
|
+
from collections.abc import Callable
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "src"))
|
|
23
|
+
|
|
24
|
+
import trkit # noqa: E402
|
|
25
|
+
|
|
26
|
+
VECTOR_FILES = (
|
|
27
|
+
"case.json",
|
|
28
|
+
"normalize.json",
|
|
29
|
+
"slug.json",
|
|
30
|
+
"mojibake.json",
|
|
31
|
+
"suffix.json",
|
|
32
|
+
"numbers.json",
|
|
33
|
+
"search.json",
|
|
34
|
+
"tokenize.json",
|
|
35
|
+
"stem.json",
|
|
36
|
+
"deasciify.json",
|
|
37
|
+
)
|
|
38
|
+
# Repo-only CC BY-SA error corpus (PLAN §10); not a conformance vector file.
|
|
39
|
+
NON_VECTOR_FILES = {"suffix.corpus.json"}
|
|
40
|
+
REQUIRED_FIELDS = ("fn", "in", "out")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _suffix(pair: list[str], **opts: Any) -> str:
|
|
44
|
+
"""suffix vectors carry [word, kind] in one `in` field (spec 03 s13)."""
|
|
45
|
+
return trkit.suffix(pair[0], pair[1], **opts)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _tokenize(text: str) -> list[list[Any]]:
|
|
49
|
+
"""Tokens are tuples; vectors store them as JSON arrays."""
|
|
50
|
+
return [list(token) for token in trkit.tokenize(text)]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _preset(_in: Any = None, **_opts: Any) -> dict:
|
|
54
|
+
return trkit.meilisearch_preset()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
FUNCTIONS: dict[str, Callable[..., Any]] = {
|
|
58
|
+
"lower": trkit.lower,
|
|
59
|
+
"upper": trkit.upper,
|
|
60
|
+
"title": trkit.title,
|
|
61
|
+
"casefold": trkit.casefold,
|
|
62
|
+
"nfc": trkit.nfc,
|
|
63
|
+
"nfd": trkit.nfd,
|
|
64
|
+
"clean": trkit.clean,
|
|
65
|
+
"fold": trkit.fold,
|
|
66
|
+
"normalize": trkit.normalize,
|
|
67
|
+
"slug": trkit.slug,
|
|
68
|
+
"fix_mojibake": trkit.fix_mojibake,
|
|
69
|
+
"suffix": _suffix,
|
|
70
|
+
"numwords": trkit.numwords,
|
|
71
|
+
"search_key": trkit.search_key,
|
|
72
|
+
"stem_f5": trkit.stem_f5,
|
|
73
|
+
"search_tokens": trkit.search_tokens,
|
|
74
|
+
"meilisearch_preset": _preset,
|
|
75
|
+
"tokenize": _tokenize,
|
|
76
|
+
"stem": trkit.stem,
|
|
77
|
+
"deasciify": trkit.deasciify,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class VectorError(RuntimeError):
|
|
82
|
+
pass
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def load(path: Path) -> dict[str, Any]:
|
|
86
|
+
try:
|
|
87
|
+
doc = json.loads(path.read_text(encoding="utf-8"))
|
|
88
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
89
|
+
raise VectorError(f"{path}: {exc}") from exc
|
|
90
|
+
for field in ("spec", "unicode", "module", "cases"):
|
|
91
|
+
if field not in doc:
|
|
92
|
+
raise VectorError(f"{path}: missing '{field}'")
|
|
93
|
+
if doc["spec"] != trkit.spec_version():
|
|
94
|
+
raise VectorError(
|
|
95
|
+
f"{path}: spec {doc['spec']} != port {trkit.spec_version()}"
|
|
96
|
+
)
|
|
97
|
+
if not isinstance(doc["cases"], list) or not doc["cases"]:
|
|
98
|
+
raise VectorError(f"{path}: 'cases' must be a non-empty list")
|
|
99
|
+
return doc
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def run_file(path: Path) -> dict[str, Any]:
|
|
103
|
+
doc = load(path)
|
|
104
|
+
mismatches: list[dict[str, Any]] = []
|
|
105
|
+
passed = xfail = 0
|
|
106
|
+
|
|
107
|
+
for index, case in enumerate(doc["cases"], start=1):
|
|
108
|
+
missing = [f for f in REQUIRED_FIELDS if f not in case]
|
|
109
|
+
if missing:
|
|
110
|
+
raise VectorError(f"{path}: case #{index} missing {missing}")
|
|
111
|
+
fn = FUNCTIONS.get(case["fn"])
|
|
112
|
+
if fn is None:
|
|
113
|
+
raise VectorError(f"{path}: unknown fn {case['fn']!r}")
|
|
114
|
+
|
|
115
|
+
actual = fn(case["in"], **(case.get("opts") or {}))
|
|
116
|
+
if actual == case["out"]:
|
|
117
|
+
passed += 1
|
|
118
|
+
continue
|
|
119
|
+
if case.get("xfail"):
|
|
120
|
+
xfail += 1
|
|
121
|
+
continue
|
|
122
|
+
mismatches.append(
|
|
123
|
+
{
|
|
124
|
+
"index": index,
|
|
125
|
+
"fn": case["fn"],
|
|
126
|
+
"in": case["in"],
|
|
127
|
+
"expected": case["out"],
|
|
128
|
+
"actual": actual,
|
|
129
|
+
"note": case.get("note", ""),
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
total = len(doc["cases"])
|
|
134
|
+
return {
|
|
135
|
+
"module": doc["module"],
|
|
136
|
+
"file": path.name,
|
|
137
|
+
"total": total,
|
|
138
|
+
"passed": passed,
|
|
139
|
+
"failed": len(mismatches),
|
|
140
|
+
"xfail": xfail,
|
|
141
|
+
"mismatches": mismatches,
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def main(argv: list[str] | None = None) -> int:
|
|
146
|
+
parser = argparse.ArgumentParser(prog="trkit-conformance")
|
|
147
|
+
parser.add_argument(
|
|
148
|
+
"--data",
|
|
149
|
+
default=str(Path(__file__).resolve().parents[3] / "data"),
|
|
150
|
+
help="directory holding vectors/*.json",
|
|
151
|
+
)
|
|
152
|
+
parser.add_argument("--module", action="append", default=[], help="limit to module(s)")
|
|
153
|
+
parser.add_argument("--json", action="store_true", dest="as_json")
|
|
154
|
+
parser.add_argument("--quiet", action="store_true")
|
|
155
|
+
args = parser.parse_args(argv)
|
|
156
|
+
|
|
157
|
+
data = Path(args.data)
|
|
158
|
+
if not data.is_dir():
|
|
159
|
+
print(f"data directory not found: {data}", file=sys.stderr)
|
|
160
|
+
return 2
|
|
161
|
+
|
|
162
|
+
paths = sorted((data / "vectors").glob("*.json")) if (data / "vectors").is_dir() else []
|
|
163
|
+
paths = [p for p in paths if p.name not in NON_VECTOR_FILES]
|
|
164
|
+
if args.module:
|
|
165
|
+
paths = [p for p in paths if p.stem in args.module]
|
|
166
|
+
if not paths:
|
|
167
|
+
print("no vector files selected", file=sys.stderr)
|
|
168
|
+
return 2
|
|
169
|
+
|
|
170
|
+
reports: list[dict[str, Any]] = []
|
|
171
|
+
try:
|
|
172
|
+
for path in paths:
|
|
173
|
+
reports.append(run_file(path))
|
|
174
|
+
except VectorError as exc:
|
|
175
|
+
print(str(exc), file=sys.stderr)
|
|
176
|
+
return 2
|
|
177
|
+
|
|
178
|
+
failed = sum(r["failed"] for r in reports)
|
|
179
|
+
total = sum(r["total"] for r in reports)
|
|
180
|
+
|
|
181
|
+
if args.as_json:
|
|
182
|
+
payload: dict[str, Any] = {
|
|
183
|
+
"spec": trkit.spec_version(),
|
|
184
|
+
"unicode": trkit.unicode_version(),
|
|
185
|
+
"total": total,
|
|
186
|
+
"passed": total - failed,
|
|
187
|
+
"failed": failed,
|
|
188
|
+
"xfail": sum(r["xfail"] for r in reports),
|
|
189
|
+
"files": reports,
|
|
190
|
+
}
|
|
191
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
|
192
|
+
elif not args.quiet:
|
|
193
|
+
for report in reports:
|
|
194
|
+
status = "PASS" if report["failed"] == 0 else "FAIL"
|
|
195
|
+
line = (
|
|
196
|
+
f"{status} {report['file']} "
|
|
197
|
+
f"{report['passed']}/{report['total']}"
|
|
198
|
+
)
|
|
199
|
+
if report["failed"]:
|
|
200
|
+
line += f" ({report['failed']} mismatch)"
|
|
201
|
+
print(line)
|
|
202
|
+
for mismatch in report["mismatches"][:20]:
|
|
203
|
+
print(
|
|
204
|
+
f" #{mismatch['index']} {mismatch['fn']} "
|
|
205
|
+
f'in={mismatch["in"]!r} '
|
|
206
|
+
f'expected={mismatch["expected"]!r} '
|
|
207
|
+
f'got={mismatch["actual"]!r}'
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
return 1 if failed else 0
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
if __name__ == "__main__":
|
|
214
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "trkit-aea"
|
|
7
|
+
version = "0.5.0"
|
|
8
|
+
description = "Turkish text hygiene for programmers: correct casing, normalization, slugging and search keys. Zero runtime dependencies."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
keywords = ["turkish", "turkce", "case", "lowercase", "slug", "normalize", "unicode", "search"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"License :: OSI Approved :: Apache Software License",
|
|
17
|
+
"Natural Language :: Turkish",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Programming Language :: Python :: 3.14",
|
|
22
|
+
"Topic :: Text Processing :: Linguistic",
|
|
23
|
+
"Typing :: Typed",
|
|
24
|
+
]
|
|
25
|
+
dependencies = []
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/akiciemir/trkit"
|
|
29
|
+
Repository = "https://github.com/akiciemir/trkit"
|
|
30
|
+
Issues = "https://github.com/akiciemir/trkit/issues"
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
dev = ["pytest>=8", "mypy>=1.11", "ruff>=0.6", "hypothesis>=6"]
|
|
34
|
+
|
|
35
|
+
[tool.hatch.build.targets.wheel]
|
|
36
|
+
packages = ["src/trkit"]
|
|
37
|
+
|
|
38
|
+
[tool.hatch.build.targets.sdist]
|
|
39
|
+
include = ["src/trkit", "tests", "conformance"]
|
|
40
|
+
|
|
41
|
+
[tool.ruff]
|
|
42
|
+
line-length = 100
|
|
43
|
+
target-version = "py311"
|
|
44
|
+
extend-exclude = ["src/trkit/_snowball"]
|
|
45
|
+
|
|
46
|
+
[tool.ruff.lint]
|
|
47
|
+
select = ["E", "F", "I", "UP", "B", "SIM"]
|
|
48
|
+
|
|
49
|
+
[tool.mypy]
|
|
50
|
+
strict = true
|
|
51
|
+
files = ["src/trkit"]
|
|
52
|
+
|
|
53
|
+
[[tool.mypy.overrides]]
|
|
54
|
+
module = "trkit._snowball.*"
|
|
55
|
+
ignore_errors = true
|
|
56
|
+
|
|
57
|
+
[[tool.mypy.overrides]]
|
|
58
|
+
module = "trkit._stem"
|
|
59
|
+
disallow_untyped_calls = false
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""trkit -- Turkish text hygiene for programmers.
|
|
2
|
+
|
|
3
|
+
Spec 1.0.0 / Unicode 16.0.0. Zero runtime dependencies.
|
|
4
|
+
|
|
5
|
+
>>> import trkit
|
|
6
|
+
>>> trkit.lower("ISPARTA")
|
|
7
|
+
'ısparta'
|
|
8
|
+
>>> trkit.title("ankara'nın kitapları")
|
|
9
|
+
"Ankara'nın Kitapları"
|
|
10
|
+
>>> trkit.slug("Çığlık Şöleni 2026!")
|
|
11
|
+
'ciglik-soleni-2026'
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from ._case import APOSTROPHES, lower, title, upper
|
|
17
|
+
from ._data import (
|
|
18
|
+
abbreviations,
|
|
19
|
+
data_manifest,
|
|
20
|
+
data_path,
|
|
21
|
+
exceptions,
|
|
22
|
+
letters,
|
|
23
|
+
load_exceptions,
|
|
24
|
+
stopwords,
|
|
25
|
+
)
|
|
26
|
+
from ._deasciify import deasciify
|
|
27
|
+
from ._normalize import casefold, clean, fix_mojibake, fold, normalize, slug
|
|
28
|
+
from ._numbers import numwords
|
|
29
|
+
from ._search import meilisearch_preset, search_key, search_tokens, stem_f5
|
|
30
|
+
from ._stem import stem
|
|
31
|
+
from ._suffix import SUFFIX_KINDS, canonical_kind, suffix
|
|
32
|
+
from ._tokenize import tokenize
|
|
33
|
+
from ._unicode import nfc, nfd, spec_version, unicode_version
|
|
34
|
+
|
|
35
|
+
__spec_version__ = spec_version()
|
|
36
|
+
|
|
37
|
+
__version__ = "0.5.0"
|
|
38
|
+
|
|
39
|
+
__all__ = [
|
|
40
|
+
# case
|
|
41
|
+
"lower",
|
|
42
|
+
"upper",
|
|
43
|
+
"title",
|
|
44
|
+
"APOSTROPHES",
|
|
45
|
+
# normalize
|
|
46
|
+
"nfc",
|
|
47
|
+
"nfd",
|
|
48
|
+
"clean",
|
|
49
|
+
"normalize",
|
|
50
|
+
"fold",
|
|
51
|
+
"casefold",
|
|
52
|
+
"slug",
|
|
53
|
+
"fix_mojibake",
|
|
54
|
+
# search
|
|
55
|
+
"search_key",
|
|
56
|
+
"stem_f5",
|
|
57
|
+
"search_tokens",
|
|
58
|
+
"meilisearch_preset",
|
|
59
|
+
# text
|
|
60
|
+
"tokenize",
|
|
61
|
+
"stem",
|
|
62
|
+
"deasciify",
|
|
63
|
+
# suffix
|
|
64
|
+
"suffix",
|
|
65
|
+
"canonical_kind",
|
|
66
|
+
"SUFFIX_KINDS",
|
|
67
|
+
"numwords",
|
|
68
|
+
# data
|
|
69
|
+
"exceptions",
|
|
70
|
+
"letters",
|
|
71
|
+
"abbreviations",
|
|
72
|
+
"stopwords",
|
|
73
|
+
"load_exceptions",
|
|
74
|
+
"data_path",
|
|
75
|
+
"data_manifest",
|
|
76
|
+
# meta
|
|
77
|
+
"spec_version",
|
|
78
|
+
"unicode_version",
|
|
79
|
+
"__spec_version__",
|
|
80
|
+
"__version__",
|
|
81
|
+
]
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Turkish-aware casing -- spec/01-case.md.
|
|
2
|
+
|
|
3
|
+
Every function is pure, NFC-normalises its input first and returns "" for "".
|
|
4
|
+
Implementation order is fixed by the spec: NFC -> Turkish table -> stdlib.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import unicodedata
|
|
10
|
+
|
|
11
|
+
from ._unicode import check_str, nfc
|
|
12
|
+
|
|
13
|
+
__all__ = ["lower", "upper", "title", "APOSTROPHES"]
|
|
14
|
+
|
|
15
|
+
# spec 01 section 2.6 -- the apostrophe set title() collapses to U+0027.
|
|
16
|
+
APOSTROPHES = frozenset("'\u2019\u02bc\u2018\u00b4`")
|
|
17
|
+
|
|
18
|
+
# spec 01 section 2.2 -- the only four code points with a non-standard mapping.
|
|
19
|
+
_L_I_LOWER = "\u0131" # I -> ı
|
|
20
|
+
_L_I_UPPER = "\u0130" # i -> İ
|
|
21
|
+
_L_DOTLESS_UPPER = "I" # ı -> I
|
|
22
|
+
|
|
23
|
+
_I_DOTTED = "i\u0307"
|
|
24
|
+
_DOT_ABOVE = "\u0307"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _nfc_tr(s: str) -> str:
|
|
28
|
+
"""NFC, plus the composition NFC deliberately skips.
|
|
29
|
+
|
|
30
|
+
U+0130 sits on Unicode's composition exclusion list, so NFC does NOT
|
|
31
|
+
recompose "i" + U+0307 back into "İ". Turkish text arrives decomposed all
|
|
32
|
+
the time, so trkit performs that one composition itself and drops any stray
|
|
33
|
+
U+0307 afterwards -- in Turkish no casing output ever keeps the dot above.
|
|
34
|
+
"""
|
|
35
|
+
return nfc(s).replace(_I_DOTTED, _L_I_UPPER)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def lower(s: str) -> str:
|
|
39
|
+
"""`I` -> `ı`, `İ` -> `i`, everything else -> standard lower().
|
|
40
|
+
|
|
41
|
+
The two code points are rewritten *before* `str.lower()` so the stdlib keeps
|
|
42
|
+
its context-sensitive behaviour for every other script (Greek final sigma).
|
|
43
|
+
"""
|
|
44
|
+
s = check_str(s, "lower")
|
|
45
|
+
if not s:
|
|
46
|
+
return ""
|
|
47
|
+
out = _nfc_tr(s).replace("I", _L_I_LOWER).replace(_L_I_UPPER, "i").lower()
|
|
48
|
+
# spec 01 section 2.7: dropping U+0307 can expose a composable pair
|
|
49
|
+
return nfc(out.replace(_DOT_ABOVE, ""))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def upper(s: str) -> str:
|
|
53
|
+
"""`i` -> `İ`, `ı` -> `I`, everything else -> standard upper()."""
|
|
54
|
+
s = check_str(s, "upper")
|
|
55
|
+
if not s:
|
|
56
|
+
return ""
|
|
57
|
+
# spec 01 P4 holds by construction: upper works on lower's output
|
|
58
|
+
out = lower(s).replace("i", _L_I_UPPER).replace(_L_DOTLESS_UPPER, "I").upper()
|
|
59
|
+
return nfc(out.replace(_DOT_ABOVE, ""))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _upper1(c: str) -> str:
|
|
63
|
+
"""Uppercase exactly one character using the Turkish table."""
|
|
64
|
+
if c == "i":
|
|
65
|
+
return _L_I_UPPER
|
|
66
|
+
if c == "\u0131":
|
|
67
|
+
return "I"
|
|
68
|
+
return c.upper()
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def title(s: str) -> str:
|
|
72
|
+
"""Title-case that does not uppercase after an apostrophe or a digit.
|
|
73
|
+
|
|
74
|
+
`"ankara'nın kitapları"` -> `"Ankara'nın Kitapları"`.
|
|
75
|
+
"""
|
|
76
|
+
s = check_str(s, "title")
|
|
77
|
+
if not s:
|
|
78
|
+
return ""
|
|
79
|
+
|
|
80
|
+
out: list[str] = []
|
|
81
|
+
at_start = True # START in the spec pseudo-code
|
|
82
|
+
for c in _nfc_tr(s):
|
|
83
|
+
if c in APOSTROPHES:
|
|
84
|
+
out.append("'")
|
|
85
|
+
at_start = False
|
|
86
|
+
continue
|
|
87
|
+
if c == _DOT_ABOVE:
|
|
88
|
+
continue
|
|
89
|
+
if unicodedata.category(c).startswith("M"):
|
|
90
|
+
out.append(c) # a combining mark belongs to the letter before it
|
|
91
|
+
continue
|
|
92
|
+
if not c.isalpha():
|
|
93
|
+
out.append(c)
|
|
94
|
+
at_start = not c.isdigit()
|
|
95
|
+
continue
|
|
96
|
+
if at_start:
|
|
97
|
+
out.append(_upper1(c))
|
|
98
|
+
at_start = False
|
|
99
|
+
else:
|
|
100
|
+
out.append(c)
|
|
101
|
+
return nfc("".join(out))
|