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.
- textloom-0.1.0/LICENSE.md +22 -0
- textloom-0.1.0/PKG-INFO +96 -0
- textloom-0.1.0/README.md +76 -0
- textloom-0.1.0/pyproject.toml +56 -0
- textloom-0.1.0/setup.cfg +4 -0
- textloom-0.1.0/src/textloom/__init__.py +16 -0
- textloom-0.1.0/src/textloom/deduplication/__init__.py +3 -0
- textloom-0.1.0/src/textloom/deduplication/names.py +28 -0
- textloom-0.1.0/src/textloom/normalization/__init__.py +9 -0
- textloom-0.1.0/src/textloom/normalization/filename.py +22 -0
- textloom-0.1.0/src/textloom/normalization/identifier.py +50 -0
- textloom-0.1.0/src/textloom/normalization/text.py +25 -0
- textloom-0.1.0/src/textloom/transliteration/__init__.py +4 -0
- textloom-0.1.0/src/textloom/transliteration/core.py +25 -0
- textloom-0.1.0/src/textloom/transliteration/mappings.py +35 -0
- textloom-0.1.0/src/textloom.egg-info/PKG-INFO +96 -0
- textloom-0.1.0/src/textloom.egg-info/SOURCES.txt +23 -0
- textloom-0.1.0/src/textloom.egg-info/dependency_links.txt +1 -0
- textloom-0.1.0/src/textloom.egg-info/requires.txt +7 -0
- textloom-0.1.0/src/textloom.egg-info/top_level.txt +1 -0
- textloom-0.1.0/tests/test_deduplication.py +7 -0
- textloom-0.1.0/tests/test_filename.py +6 -0
- textloom-0.1.0/tests/test_identifier.py +8 -0
- textloom-0.1.0/tests/test_normalization.py +6 -0
- textloom-0.1.0/tests/test_transliteration.py +9 -0
|
@@ -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.
|
textloom-0.1.0/PKG-INFO
ADDED
|
@@ -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
|
+
[](https://github.com/avtomatik/textloom/actions/workflows/ci.yml)
|
|
24
|
+
[](https://pypi.org/project/textloom/)
|
|
25
|
+
[](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.
|
textloom-0.1.0/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# TextLoom
|
|
2
|
+
|
|
3
|
+
[](https://github.com/avtomatik/textloom/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/textloom/)
|
|
5
|
+
[](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
|
textloom-0.1.0/setup.cfg
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,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,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,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
|
+
[](https://github.com/avtomatik/textloom/actions/workflows/ci.yml)
|
|
24
|
+
[](https://pypi.org/project/textloom/)
|
|
25
|
+
[](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 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
textloom
|
|
@@ -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,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("") == ""
|