textloom 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.
textloom/__init__.py ADDED
@@ -0,0 +1,16 @@
1
+ from .deduplication import deduplicate_names
2
+ from .normalization import (
3
+ normalize_filename,
4
+ normalize_identifier,
5
+ normalize_text,
6
+ )
7
+ from .transliteration import transliterate
8
+
9
+ __all__ = [
10
+ "tl",
11
+ "transliterate",
12
+ "normalize_identifier",
13
+ "normalize_filename",
14
+ "normalize_text",
15
+ "deduplicate_names",
16
+ ]
@@ -0,0 +1,3 @@
1
+ from .names import deduplicate_names
2
+
3
+ __all__ = ["deduplicate_names"]
@@ -0,0 +1,28 @@
1
+ from collections import defaultdict
2
+ from typing import DefaultDict, Iterable, List
3
+
4
+
5
+ def deduplicate_names(
6
+ values: Iterable[str],
7
+ separator: str = "_",
8
+ ) -> List[str]:
9
+ """
10
+ Make names unique while preserving order.
11
+
12
+ Example:
13
+ ["a", "a", "a"] ->
14
+ ["a", "a_2", "a_3"]
15
+ """
16
+
17
+ counts: DefaultDict[str, int] = defaultdict(int)
18
+ result = []
19
+
20
+ for value in values:
21
+ counts[value] += 1
22
+
23
+ if counts[value] == 1:
24
+ result.append(value)
25
+ else:
26
+ result.append(f"{value}{separator}{counts[value]}")
27
+
28
+ return result
@@ -0,0 +1,9 @@
1
+ from .filename import normalize_filename
2
+ from .identifier import normalize_identifier
3
+ from .text import normalize_text
4
+
5
+ __all__ = [
6
+ "normalize_text",
7
+ "normalize_identifier",
8
+ "normalize_filename",
9
+ ]
@@ -0,0 +1,22 @@
1
+ from pathlib import Path
2
+
3
+ from .identifier import normalize_identifier
4
+
5
+
6
+ def normalize_filename(name: str) -> str:
7
+ """
8
+ Normalize a filename into a filesystem-friendly slug.
9
+
10
+ Example:
11
+ "Мой файл.xlsx" -> "moy-fayl.xlsx"
12
+ """
13
+ path = Path(name)
14
+
15
+ stem = normalize_identifier(
16
+ path.stem,
17
+ separator="-",
18
+ )
19
+
20
+ suffix = "".join(path.suffixes).lower()
21
+
22
+ return f"{stem}{suffix}"
@@ -0,0 +1,50 @@
1
+ import re
2
+ import unicodedata
3
+
4
+ from ..transliteration.core import transliterate
5
+
6
+
7
+ def normalize_identifier(
8
+ value: str,
9
+ *,
10
+ separator: str = "_",
11
+ lowercase: bool = True,
12
+ transliterate_cyrillic: bool = True,
13
+ ascii_only: bool = True,
14
+ collapse_separators: bool = True,
15
+ strip_separators: bool = True,
16
+ ) -> str:
17
+ """
18
+ Normalize arbitrary text into a clean identifier.
19
+
20
+ Examples:
21
+ "Цена товара" -> "cena_tovara"
22
+ "Revenue ($)" -> "revenue"
23
+ """
24
+
25
+ text = unicodedata.normalize("NFKC", str(value))
26
+
27
+ if transliterate_cyrillic:
28
+ text = transliterate(text)
29
+
30
+ if lowercase:
31
+ text = text.lower()
32
+
33
+ if ascii_only:
34
+ pattern = r"[^a-z0-9]+"
35
+ else:
36
+ pattern = r"\W+"
37
+
38
+ text = re.sub(pattern, separator, text)
39
+
40
+ if collapse_separators:
41
+ text = re.sub(
42
+ rf"{re.escape(separator)}+",
43
+ separator,
44
+ text,
45
+ )
46
+
47
+ if strip_separators:
48
+ text = text.strip(separator)
49
+
50
+ return text
@@ -0,0 +1,25 @@
1
+ import re
2
+ import unicodedata
3
+
4
+ from ..transliteration.core import transliterate
5
+
6
+
7
+ def normalize_text(
8
+ text: str,
9
+ *,
10
+ lowercase: bool = True,
11
+ transliterate_cyrillic: bool = True,
12
+ collapse_whitespace: bool = True,
13
+ ) -> str:
14
+ text = unicodedata.normalize("NFKC", str(text))
15
+
16
+ if transliterate_cyrillic:
17
+ text = transliterate(text)
18
+
19
+ if lowercase:
20
+ text = text.lower()
21
+
22
+ if collapse_whitespace:
23
+ text = re.sub(r"\s+", " ", text).strip()
24
+
25
+ return text
@@ -0,0 +1,4 @@
1
+ from .core import transliterate
2
+ from .mappings import CYRILLIC_TO_LATIN
3
+
4
+ __all__ = ["CYRILLIC_TO_LATIN", "transliterate"]
@@ -0,0 +1,25 @@
1
+ from .mappings import CYRILLIC_TO_LATIN
2
+
3
+
4
+ def transliterate(text: str) -> str:
5
+ """
6
+ Transliterate Russian Cyrillic text to Latin.
7
+
8
+ Example:
9
+ Привет -> Privet
10
+ """
11
+ result = []
12
+
13
+ for char in text:
14
+ mapped = CYRILLIC_TO_LATIN.get(char.lower())
15
+
16
+ if mapped is None:
17
+ result.append(char)
18
+ continue
19
+
20
+ if char.isupper():
21
+ mapped = mapped[0].upper() + mapped[1:]
22
+
23
+ result.append(mapped)
24
+
25
+ return "".join(result)
@@ -0,0 +1,35 @@
1
+ CYRILLIC_TO_LATIN = {
2
+ "а": "a",
3
+ "б": "b",
4
+ "в": "v",
5
+ "г": "g",
6
+ "д": "d",
7
+ "е": "e",
8
+ "ё": "yo",
9
+ "ж": "zh",
10
+ "з": "z",
11
+ "и": "i",
12
+ "й": "y",
13
+ "к": "k",
14
+ "л": "l",
15
+ "м": "m",
16
+ "н": "n",
17
+ "о": "o",
18
+ "п": "p",
19
+ "р": "r",
20
+ "с": "s",
21
+ "т": "t",
22
+ "у": "u",
23
+ "ф": "f",
24
+ "х": "kh",
25
+ "ц": "ts",
26
+ "ч": "ch",
27
+ "ш": "sh",
28
+ "щ": "shch",
29
+ "ъ": "",
30
+ "ы": "y",
31
+ "ь": "",
32
+ "э": "e",
33
+ "ю": "yu",
34
+ "я": "ya",
35
+ }
@@ -0,0 +1,96 @@
1
+ Metadata-Version: 2.4
2
+ Name: textloom
3
+ Version: 0.1.0
4
+ Summary: Lightweight text processing utilities for normalization, transliteration, and deduplication
5
+ Author: Alexander
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/avtomatik/textloom
8
+ Project-URL: Repository, https://github.com/avtomatik/textloom
9
+ Project-URL: Issues, https://github.com/avtomatik/textloom/issues
10
+ Requires-Python: >=3.8
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE.md
13
+ Provides-Extra: dev
14
+ Requires-Dist: pytest; extra == "dev"
15
+ Requires-Dist: mypy; extra == "dev"
16
+ Requires-Dist: ruff; extra == "dev"
17
+ Requires-Dist: build; extra == "dev"
18
+ Requires-Dist: twine; extra == "dev"
19
+ Dynamic: license-file
20
+
21
+ # TextLoom
22
+
23
+ [![Lint](https://github.com/avtomatik/textloom/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/avtomatik/textloom/actions/workflows/ci.yml)
24
+ [![Python Version](https://img.shields.io/pypi/pyversions/textloom)](https://pypi.org/project/textloom/)
25
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
26
+
27
+ Lightweight text processing utilities for Python.
28
+
29
+ TextLoom provides a small collection of reusable tools for:
30
+
31
+ * Transliteration
32
+ * Text normalization
33
+ * Identifier generation
34
+ * Filename normalization
35
+ * Name deduplication
36
+
37
+ The library was extracted from larger data-processing projects to provide a focused and **dependency-free toolkit** for text handling.
38
+
39
+ ## Installation
40
+
41
+ ```bash
42
+ pip install textloom
43
+ ````
44
+
45
+ ## Usage
46
+
47
+ ```python
48
+ import textloom as tl
49
+ ```
50
+
51
+ ### Transliteration
52
+
53
+ ```python
54
+ tl.transliterate("Привет Мир")
55
+ # "Privet Mir"
56
+ ```
57
+
58
+ ### Text normalization
59
+
60
+ ```python
61
+ tl.normalize_text(" Привет Мир ")
62
+ # "privet mir"
63
+ ```
64
+
65
+ ### Identifier normalization
66
+
67
+ ```python
68
+ tl.normalize_identifier("Цена товара")
69
+ # "tsena_tovara"
70
+ ```
71
+
72
+ ### Filename normalization
73
+
74
+ ```python
75
+ tl.normalize_filename("Мой файл.xlsx")
76
+ # "moy-fayl.xlsx"
77
+ ```
78
+
79
+ ### Deduplication
80
+
81
+ ```python
82
+ tl.deduplicate_names(["name", "name", "name"])
83
+ # ["name", "name_2", "name_3"]
84
+ ```
85
+
86
+ ## Design Goals
87
+
88
+ * Zero runtime dependencies
89
+ * Predictable behavior
90
+ * Small, intuitive API
91
+ * Reusable across projects
92
+ * Easy to extend
93
+
94
+ ## License
95
+
96
+ MIT License. See the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,15 @@
1
+ textloom/__init__.py,sha256=-WKMMVmPxyJUlD5yfxQsPhRSouTtnYWuWS4DdoQ-btU,336
2
+ textloom/deduplication/__init__.py,sha256=woUb3GUjj-j62eAhYaGJtdCpdFXjBKU3UBzx1onEefA,70
3
+ textloom/deduplication/names.py,sha256=suQ1jbDHG2QYPvF9Hq543u9MrZ7DpuugMPV9GoS1DI4,593
4
+ textloom/normalization/__init__.py,sha256=Ycx450dObh-FTQb4YJYPxYas_qXIo7a3QibDZTWPb0o,210
5
+ textloom/normalization/filename.py,sha256=Ys8U2bQMxZQN7KY3WcA_d-4Z6cNx-rZRJVPA5CmvsjM,432
6
+ textloom/normalization/identifier.py,sha256=QErSzmj1GE-1UV8e4fmepUWEZe8bpXZOpBusv2wBz5g,1030
7
+ textloom/normalization/text.py,sha256=MecXnhN43jvB6xREoacSnHUp22aZkK1-GUzoz6W9voA,501
8
+ textloom/transliteration/__init__.py,sha256=QHy24Ynnx750IlCZWcnfhfj2l1NlAzmseM47uiuIfMw,122
9
+ textloom/transliteration/core.py,sha256=neq-NcYcbjr_jXRChC9_ePRZV7SJD3p2N-tKTP57LeY,502
10
+ textloom/transliteration/mappings.py,sha256=MGFmkaHFjUv33jjd4qBk23_k1wKUBiVShG88xg-5GCQ,528
11
+ textloom-0.1.0.dist-info/licenses/LICENSE.md,sha256=6fecqwcSmq46iz-eLCvg8CqlZPIhek-4S4PosuWLlFY,1087
12
+ textloom-0.1.0.dist-info/METADATA,sha256=HYJHK89OvJ2kP_piZfaU4iDfouN7pGUYEyIdrRPiOP0,2230
13
+ textloom-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
14
+ textloom-0.1.0.dist-info/top_level.txt,sha256=rldH3qKV3keqTeu-l48-YKufxobcm8TJBB3y_l2x-ck,9
15
+ textloom-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,22 @@
1
+
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2026 Alexander Mikhailov
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ textloom