textloom 0.1.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,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,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,76 @@
1
+ # TextLoom
2
+
3
+ [![Lint](https://github.com/avtomatik/textloom/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/avtomatik/textloom/actions/workflows/ci.yml)
4
+ [![Python Version](https://img.shields.io/pypi/pyversions/textloom)](https://pypi.org/project/textloom/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+
7
+ Lightweight text processing utilities for Python.
8
+
9
+ TextLoom provides a small collection of reusable tools for:
10
+
11
+ * Transliteration
12
+ * Text normalization
13
+ * Identifier generation
14
+ * Filename normalization
15
+ * Name deduplication
16
+
17
+ The library was extracted from larger data-processing projects to provide a focused and **dependency-free toolkit** for text handling.
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pip install textloom
23
+ ````
24
+
25
+ ## Usage
26
+
27
+ ```python
28
+ import textloom as tl
29
+ ```
30
+
31
+ ### Transliteration
32
+
33
+ ```python
34
+ tl.transliterate("Привет Мир")
35
+ # "Privet Mir"
36
+ ```
37
+
38
+ ### Text normalization
39
+
40
+ ```python
41
+ tl.normalize_text(" Привет Мир ")
42
+ # "privet mir"
43
+ ```
44
+
45
+ ### Identifier normalization
46
+
47
+ ```python
48
+ tl.normalize_identifier("Цена товара")
49
+ # "tsena_tovara"
50
+ ```
51
+
52
+ ### Filename normalization
53
+
54
+ ```python
55
+ tl.normalize_filename("Мой файл.xlsx")
56
+ # "moy-fayl.xlsx"
57
+ ```
58
+
59
+ ### Deduplication
60
+
61
+ ```python
62
+ tl.deduplicate_names(["name", "name", "name"])
63
+ # ["name", "name_2", "name_3"]
64
+ ```
65
+
66
+ ## Design Goals
67
+
68
+ * Zero runtime dependencies
69
+ * Predictable behavior
70
+ * Small, intuitive API
71
+ * Reusable across projects
72
+ * Easy to extend
73
+
74
+ ## License
75
+
76
+ MIT License. See the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,56 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "textloom"
7
+ version = "0.1.0"
8
+ description = "Lightweight text processing utilities for normalization, transliteration, and deduplication"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = {text = "MIT"}
12
+ authors = [
13
+ {name = "Alexander"}
14
+ ]
15
+
16
+ dependencies = []
17
+
18
+ [project.urls]
19
+ Homepage = "https://github.com/avtomatik/textloom"
20
+ Repository = "https://github.com/avtomatik/textloom"
21
+ Issues = "https://github.com/avtomatik/textloom/issues"
22
+
23
+ [project.optional-dependencies]
24
+ dev = [
25
+ "pytest",
26
+ "mypy",
27
+ "ruff",
28
+ "build",
29
+ "twine",
30
+ ]
31
+
32
+ [tool.setuptools]
33
+ package-dir = {"" = "src"}
34
+
35
+ [tool.setuptools.packages.find]
36
+ where = ["src"]
37
+
38
+ [tool.ruff]
39
+ line-length = 79
40
+ target-version = "py38"
41
+
42
+ [tool.ruff.lint]
43
+ select = ["E", "F", "I", "UP", "B"]
44
+
45
+ [tool.ruff.format]
46
+ quote-style = "double"
47
+ indent-style = "space"
48
+
49
+ [tool.mypy]
50
+ python_version = "3.10"
51
+ strict = true
52
+ exclude = "tests/"
53
+
54
+ [[tool.mypy.overrides]]
55
+ module = "tests.*"
56
+ disallow_untyped_defs = false
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -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,23 @@
1
+ LICENSE.md
2
+ README.md
3
+ pyproject.toml
4
+ src/textloom/__init__.py
5
+ src/textloom.egg-info/PKG-INFO
6
+ src/textloom.egg-info/SOURCES.txt
7
+ src/textloom.egg-info/dependency_links.txt
8
+ src/textloom.egg-info/requires.txt
9
+ src/textloom.egg-info/top_level.txt
10
+ src/textloom/deduplication/__init__.py
11
+ src/textloom/deduplication/names.py
12
+ src/textloom/normalization/__init__.py
13
+ src/textloom/normalization/filename.py
14
+ src/textloom/normalization/identifier.py
15
+ src/textloom/normalization/text.py
16
+ src/textloom/transliteration/__init__.py
17
+ src/textloom/transliteration/core.py
18
+ src/textloom/transliteration/mappings.py
19
+ tests/test_deduplication.py
20
+ tests/test_filename.py
21
+ tests/test_identifier.py
22
+ tests/test_normalization.py
23
+ tests/test_transliteration.py
@@ -0,0 +1,7 @@
1
+
2
+ [dev]
3
+ pytest
4
+ mypy
5
+ ruff
6
+ build
7
+ twine
@@ -0,0 +1 @@
1
+ textloom
@@ -0,0 +1,7 @@
1
+ import textloom as tl
2
+
3
+
4
+ def test_deduplicate_names():
5
+ assert tl.deduplicate_names(["a", "a", "a"]) == ["a", "a_2", "a_3"]
6
+ assert tl.deduplicate_names(["a", "b", "a"]) == ["a", "b", "a_2"]
7
+ assert tl.deduplicate_names([]) == []
@@ -0,0 +1,6 @@
1
+ import textloom as tl
2
+
3
+
4
+ def test_filename():
5
+ assert tl.normalize_filename("Мой файл.xlsx") == "moy-fayl.xlsx"
6
+ assert tl.normalize_filename("My File.xlsx") == "my-file.xlsx"
@@ -0,0 +1,8 @@
1
+ import textloom as tl
2
+
3
+
4
+ def test_identifier():
5
+ assert tl.normalize_identifier("Revenue ($)") == "revenue"
6
+ assert tl.normalize_identifier("___A___") == "a"
7
+ assert tl.normalize_identifier("Цена товара") == "tsena_tovara"
8
+ assert tl.normalize_identifier("") == ""
@@ -0,0 +1,6 @@
1
+ import textloom as tl
2
+
3
+
4
+ def test_normalize_text():
5
+ assert tl.normalize_text(" Hello World ") == "hello world"
6
+ assert tl.normalize_text("Привет Мир") == "privet mir"
@@ -0,0 +1,9 @@
1
+ import textloom as tl
2
+
3
+
4
+ def test_transliterate():
5
+ assert tl.transliterate("Привет") == "Privet"
6
+ assert tl.transliterate("123") == "123"
7
+ assert tl.transliterate("Привет, World!") == "Privet, World!"
8
+ assert tl.transliterate("Ёж") == "Yozh"
9
+ assert tl.transliterate("") == ""