lexitrace 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
lexitrace/__init__.py ADDED
@@ -0,0 +1,53 @@
1
+ """Turkish-aware text helpers of the LexiTrace project."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ import unicodedata
7
+
8
+ __version__ = "0.1.0"
9
+ __all__ = [
10
+ "APOSTROPHES",
11
+ "fold_circumflex",
12
+ "normalize_apostrophes",
13
+ "search_key",
14
+ "tr_lower",
15
+ "tr_upper",
16
+ ]
17
+
18
+ _LOWER_I = str.maketrans({"I": "ı", "İ": "i"})
19
+ _UPPER_I = str.maketrans({"i": "İ", "ı": "I"})
20
+ # Î is the capital of î, the dotted i with a circumflex, so it folds to the dotted capital İ.
21
+ _FOLD = str.maketrans("âîûÂÎÛ", "aiuAİU")
22
+ #: The apostrophe shapes that printed and scanned Turkish text uses.
23
+ APOSTROPHES = "’‘ʼ`´‟"
24
+ _APOSTROPHE_MAP = str.maketrans({ch: "'" for ch in APOSTROPHES})
25
+ _SPACES = re.compile(r"\s+")
26
+
27
+
28
+ def tr_lower(text: str) -> str:
29
+ """Turkish lower-casing: I becomes ı and İ becomes i, then the rest as usual."""
30
+ return text.translate(_LOWER_I).lower()
31
+
32
+
33
+ def tr_upper(text: str) -> str:
34
+ """Turkish upper-casing: i becomes İ and ı becomes I, then the rest as usual."""
35
+ return text.translate(_UPPER_I).upper()
36
+
37
+
38
+ def fold_circumflex(text: str) -> str:
39
+ """Fold the circumflex vowels: â to a, î to i, û to u, and their capitals."""
40
+ return text.translate(_FOLD)
41
+
42
+
43
+ def normalize_apostrophes(text: str) -> str:
44
+ """Map every apostrophe shape of APOSTROPHES to the ASCII apostrophe. Keeps the length."""
45
+ return text.translate(_APOSTROPHE_MAP)
46
+
47
+
48
+ def search_key(text: str) -> str:
49
+ """A key for matching what a user types to a word: NFC, Turkish lower case, no
50
+ circumflex, no apostrophe, single spaces."""
51
+ key = fold_circumflex(tr_lower(unicodedata.normalize("NFC", text)))
52
+ key = normalize_apostrophes(key).replace("'", "")
53
+ return _SPACES.sub(" ", key).strip()
lexitrace/py.typed ADDED
File without changes
@@ -0,0 +1,52 @@
1
+ Metadata-Version: 2.5
2
+ Name: lexitrace
3
+ Version: 0.1.0
4
+ Summary: Turkish-aware text helpers of the LexiTrace project: casing with dotted and dotless i, circumflex folding, apostrophe normalising and search keys.
5
+ Author: Batuhan Duras
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Keywords: casing,nlp,normalization,text,turkish
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Natural Language :: Turkish
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Text Processing :: Linguistic
14
+ Classifier: Typing :: Typed
15
+ Requires-Python: >=3.9
16
+ Description-Content-Type: text/markdown
17
+
18
+ # lexitrace
19
+
20
+ Turkish-aware text helpers of the LexiTrace project: casing with dotted and dotless i, circumflex folding, apostrophe normalising and search keys.
21
+
22
+ Plain lower-casing is wrong for Turkish. `I` is the capital of `ı`, and `İ` is the capital of `i`, so `ISPARTA` shall become `ısparta`, not `isparta`. Older texts also write `â`, `î` and `û`, and they print the apostrophe in six shapes. These helpers apply the rules that the LexiTrace project uses when it counts and searches words.
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ pip install lexitrace
28
+ ```
29
+
30
+ ## Use
31
+
32
+ ```python
33
+ from lexitrace import tr_lower, tr_upper, fold_circumflex, normalize_apostrophes, search_key
34
+
35
+ tr_lower("ISPARTA İZMİR") # "ısparta izmir"
36
+ tr_upper("ırmak izmir") # "IRMAK İZMİR"
37
+ fold_circumflex("hükûmet kâtip") # "hükumet katip"
38
+ normalize_apostrophes("Hatay’ın") # "Hatay'ın"
39
+ search_key(" MİLLÎ Eğitim’in ") # "milli eğitimin"
40
+ ```
41
+
42
+ No dependencies. Python 3.9 or newer.
43
+
44
+ ## About
45
+
46
+ LexiTrace is a study of word replacement in Turkish parliamentary records from 1928 to 2024, by Batuhan Duras. This package holds its text helpers. More of the project may follow under this name.
47
+
48
+ Written with the help of Claude Code (Anthropic).
49
+
50
+ ## License
51
+
52
+ MIT.
@@ -0,0 +1,6 @@
1
+ lexitrace/__init__.py,sha256=puvlwIYoCmZp591-Tu22_BgqWFaii4271U05sfoPuK8,1731
2
+ lexitrace/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ lexitrace-0.1.0.dist-info/METADATA,sha256=xnFGjoD8pVnqudsuaBWQ7ZEWwwC2rnCbbf8vsnQqQ2o,1912
4
+ lexitrace-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
5
+ lexitrace-0.1.0.dist-info/licenses/LICENSE,sha256=ufVT-__hPt0Q9yx8VFaYj9dnoTChIcXQ3vv6LUyP3jU,1070
6
+ lexitrace-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Batuhan Duras
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.