text-utils-vn 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.
text_utils_vn/core.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Các hàm xử lý văn bản tiếng Việt."""
|
|
2
|
+
import unicodedata
|
|
3
|
+
|
|
4
|
+
STOPWORDS = {"tôi", "bạn", "là", "và", "của", "có", "những", "các", "một", "được", "này", "đó"}
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def remove_accents(text: str) -> str:
|
|
8
|
+
"""
|
|
9
|
+
Bỏ dấu tiếng Việt: 'Tiếng Việt' -> 'Tieng Viet'.
|
|
10
|
+
:param: text: Chuỗi văn bản đầu vào
|
|
11
|
+
:return: Chuỗi văn bản sau khi đã bỏ dấu
|
|
12
|
+
"""
|
|
13
|
+
text = text.replace("đ", "d").replace("Đ", "D")
|
|
14
|
+
text = unicodedata.normalize("NFD", text)
|
|
15
|
+
text = "".join(c for c in text if unicodedata.category(c) != "Mn")
|
|
16
|
+
return unicodedata.normalize("NFC", text)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def normalize_text(text: str) -> str:
|
|
20
|
+
"""
|
|
21
|
+
Chữ thường, bỏ khoảng trắng thừa.
|
|
22
|
+
:param: text: Chuỗi văn bản đầu vào
|
|
23
|
+
:return: Chuỗi văn bản sau khi được chuẩn hóa
|
|
24
|
+
"""
|
|
25
|
+
text = unicodedata.normalize("NFC", text)
|
|
26
|
+
return " ".join(text.lower().split())
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def count_words(text: str) -> int:
|
|
31
|
+
"""
|
|
32
|
+
Đếm số từ (tách theo khoảng trắng).
|
|
33
|
+
:param: text: Chuỗi văn bản đầu vào
|
|
34
|
+
:return: Số lượng từ trong chuỗi văn bản"""
|
|
35
|
+
return len(text.split())
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def remove_stopwords(text: str) -> str:
|
|
39
|
+
"""
|
|
40
|
+
Bỏ các từ trong STOPWORDS.
|
|
41
|
+
:param: text: Chuỗi văn bản đầu vào
|
|
42
|
+
:return: Chuỗi văn bản sau khi bỏ stopwords
|
|
43
|
+
"""
|
|
44
|
+
words = text.split()
|
|
45
|
+
filtered_words = [word for word in words if word.lower() not in STOPWORDS]
|
|
46
|
+
return " ".join(filtered_words)
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: text-utils-vn
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Các hàm tiện ích xử lý văn bản tiếng Việt
|
|
5
|
+
Author: Nguyen Bao Duy
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: vietnamese,nlp,text-processing
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Natural Language :: Vietnamese
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Provides-Extra: test
|
|
15
|
+
Requires-Dist: pytest; extra == "test"
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# text-utils-vn
|
|
19
|
+
|
|
20
|
+
Thư viện nhỏ gồm các hàm xử lý văn bản tiếng Việt: bỏ dấu, chuẩn hóa chuỗi, đếm từ và loại bỏ từ dừng (stopword).
|
|
21
|
+
|
|
22
|
+
## Cài đặt
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install text-utils-vn
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Cách dùng
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from text_utils_vn import remove_accents, normalize_text, count_words, remove_stopwords
|
|
32
|
+
|
|
33
|
+
remove_accents("Tiếng Việt") # 'Tieng Viet'
|
|
34
|
+
normalize_text(" Xin CHÀO bạn ") # 'xin chào bạn'
|
|
35
|
+
count_words("hôm nay trời đẹp") # 4
|
|
36
|
+
remove_stopwords("tôi là sinh viên") # 'sinh viên'
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Các hàm
|
|
40
|
+
|
|
41
|
+
| Hàm | Mô tả |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `remove_accents(text)` | Bỏ dấu tiếng Việt, kể cả chữ `đ` / `Đ` |
|
|
44
|
+
| `normalize_text(text)` | Chuẩn hóa Unicode (NFC), chuyển chữ thường, gộp khoảng trắng thừa |
|
|
45
|
+
| `count_words(text)` | Đếm số từ tách theo khoảng trắng |
|
|
46
|
+
| `remove_stopwords(text)` | Bỏ các từ dừng thông dụng trong một danh sách nhỏ có sẵn |
|
|
47
|
+
|
|
48
|
+
## Lưu ý
|
|
49
|
+
|
|
50
|
+
- `count_words` tách theo khoảng trắng nên thực chất đếm âm tiết, ví dụ "sinh viên" được tính là 2.
|
|
51
|
+
- Danh sách stopword có sẵn chỉ gồm một số từ phổ biến, mang tính minh họa.
|
|
52
|
+
|
|
53
|
+
## Chạy test
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install -e ".[test]"
|
|
57
|
+
pytest
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Giấy phép
|
|
61
|
+
|
|
62
|
+
MIT License
|
|
63
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
text_utils_vn/__init__.py,sha256=0dGktrO17f73jJFitwvDtyttznJ73YmXY0EZqKILd2w,187
|
|
2
|
+
text_utils_vn/core.py,sha256=6bcHSCtl7lOhUwvFveFuxXIPrkwkRSfqVI4JDdGz_cg,1555
|
|
3
|
+
text_utils_vn-0.1.0.dist-info/licenses/LICENSE,sha256=g97gef-x4jJZ_RTXcoQCtouJdHQ0jWWiFLRJIASTai4,1081
|
|
4
|
+
text_utils_vn-0.1.0.dist-info/METADATA,sha256=jMEUJfotjdNMnjwL1NViX7qscRFNAMrPpUI6rIx2XKc,1897
|
|
5
|
+
text_utils_vn-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
6
|
+
text_utils_vn-0.1.0.dist-info/top_level.txt,sha256=GKQ7Y-qQXkDpO-I0gU2_IReU_yzhaTRk-RtPvHO1jJc,14
|
|
7
|
+
text_utils_vn-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) [2026] [Nguyen Bao Duy]
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
text_utils_vn
|