arabic-normalizer 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.
- arabic_normalizer-0.1.0/.github/workflows/publish.yml +20 -0
- arabic_normalizer-0.1.0/.github/workflows/tests.yml +17 -0
- arabic_normalizer-0.1.0/.gitignore +223 -0
- arabic_normalizer-0.1.0/LICENSE +21 -0
- arabic_normalizer-0.1.0/PKG-INFO +40 -0
- arabic_normalizer-0.1.0/README.md +25 -0
- arabic_normalizer-0.1.0/arabic_normalizer/__init__.py +50 -0
- arabic_normalizer-0.1.0/pyproject.toml +21 -0
- arabic_normalizer-0.1.0/tests/test_normalize.py +46 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
environment: pypi
|
|
11
|
+
permissions:
|
|
12
|
+
id-token: write
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v5
|
|
15
|
+
- uses: actions/setup-python@v6
|
|
16
|
+
with:
|
|
17
|
+
python-version: "3.13"
|
|
18
|
+
- run: pip install build
|
|
19
|
+
- run: python -m build
|
|
20
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
name: tests
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
test:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
strategy:
|
|
9
|
+
matrix:
|
|
10
|
+
python-version: ["3.10", "3.12", "3.13"]
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v5
|
|
13
|
+
- uses: actions/setup-python@v6
|
|
14
|
+
with:
|
|
15
|
+
python-version: ${{ matrix.python-version }}
|
|
16
|
+
- run: pip install -e . pytest
|
|
17
|
+
- run: pytest
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
*.lcov
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
# Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# uv
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# uv.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
# poetry.lock
|
|
110
|
+
# poetry.toml
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
115
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
116
|
+
# pdm.lock
|
|
117
|
+
# pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# pixi
|
|
122
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
123
|
+
# pixi.lock
|
|
124
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
125
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
126
|
+
.pixi/*
|
|
127
|
+
!.pixi/config.toml
|
|
128
|
+
|
|
129
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
130
|
+
__pypackages__/
|
|
131
|
+
|
|
132
|
+
# Celery stuff
|
|
133
|
+
celerybeat-schedule*
|
|
134
|
+
celerybeat.pid
|
|
135
|
+
|
|
136
|
+
# Redis
|
|
137
|
+
*.rdb
|
|
138
|
+
*.aof
|
|
139
|
+
*.pid
|
|
140
|
+
|
|
141
|
+
# RabbitMQ
|
|
142
|
+
mnesia/
|
|
143
|
+
rabbitmq/
|
|
144
|
+
rabbitmq-data/
|
|
145
|
+
|
|
146
|
+
# ActiveMQ
|
|
147
|
+
activemq-data/
|
|
148
|
+
|
|
149
|
+
# SageMath parsed files
|
|
150
|
+
*.sage.py
|
|
151
|
+
|
|
152
|
+
# Environments
|
|
153
|
+
.env
|
|
154
|
+
.envrc
|
|
155
|
+
.venv
|
|
156
|
+
env/
|
|
157
|
+
venv/
|
|
158
|
+
ENV/
|
|
159
|
+
env.bak/
|
|
160
|
+
venv.bak/
|
|
161
|
+
|
|
162
|
+
# Conda environments
|
|
163
|
+
conda-meta/
|
|
164
|
+
|
|
165
|
+
# Spyder project settings
|
|
166
|
+
.spyderproject
|
|
167
|
+
.spyproject
|
|
168
|
+
|
|
169
|
+
# Rope project settings
|
|
170
|
+
.ropeproject
|
|
171
|
+
|
|
172
|
+
# mkdocs/Zensical documentation
|
|
173
|
+
/site
|
|
174
|
+
|
|
175
|
+
# mypy
|
|
176
|
+
.mypy_cache/
|
|
177
|
+
.dmypy.json
|
|
178
|
+
dmypy.json
|
|
179
|
+
|
|
180
|
+
# Pyre type checker
|
|
181
|
+
.pyre/
|
|
182
|
+
|
|
183
|
+
# pytype static type analyzer
|
|
184
|
+
.pytype/
|
|
185
|
+
|
|
186
|
+
# Cython debug symbols
|
|
187
|
+
cython_debug/
|
|
188
|
+
|
|
189
|
+
# PyCharm
|
|
190
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
191
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
192
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
193
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
194
|
+
# .idea/
|
|
195
|
+
|
|
196
|
+
# Abstra
|
|
197
|
+
# Abstra is an AI-powered process automation framework.
|
|
198
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
199
|
+
# Learn more at https://abstra.io/docs
|
|
200
|
+
.abstra/
|
|
201
|
+
|
|
202
|
+
# Visual Studio Code
|
|
203
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
|
|
204
|
+
# can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
205
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer, you
|
|
206
|
+
# could uncomment the following to ignore the entire vscode folder
|
|
207
|
+
# .vscode/
|
|
208
|
+
# Temporary file for partial code execution
|
|
209
|
+
tempCodeRunnerFile.py
|
|
210
|
+
|
|
211
|
+
# Ruff stuff:
|
|
212
|
+
.ruff_cache/
|
|
213
|
+
|
|
214
|
+
# PyPI configuration file
|
|
215
|
+
.pypirc
|
|
216
|
+
|
|
217
|
+
# Marimo
|
|
218
|
+
marimo/_static/
|
|
219
|
+
marimo/_lsp/
|
|
220
|
+
__marimo__/
|
|
221
|
+
|
|
222
|
+
# Streamlit
|
|
223
|
+
.streamlit/secrets.toml
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 azizalkhayal-netizen
|
|
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.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: arabic-normalizer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lightweight Arabic text normalization for search and NLP
|
|
5
|
+
Project-URL: Homepage, https://github.com/azizalkhayal-netizen/arabic-normalizer
|
|
6
|
+
Author: Abdulaziz Alkhayyal
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: arabic,nlp,normalization,text
|
|
10
|
+
Classifier: Natural Language :: Arabic
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# arabic-normalizer
|
|
17
|
+
|
|
18
|
+
A lightweight Python library for cleaning and normalizing Arabic text, with no dependencies.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
```
|
|
22
|
+
pip install arabic-normalizer
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
- Remove diacritics (tashkeel) and tatweel
|
|
27
|
+
- Unify alef forms (أ إ آ → ا) and ى → ي
|
|
28
|
+
- Convert Arabic-Indic digits (٠١٢) to 0-9
|
|
29
|
+
- Optional ة → ه normalization
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
```python
|
|
33
|
+
from arabic_normalizer import normalize
|
|
34
|
+
|
|
35
|
+
normalize("أَهْلاً بِكُمْ فِي الرِّيَاضِ ٢٠٢٦")
|
|
36
|
+
# 'اهلا بكم في الرياض 2026'
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
MIT
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# arabic-normalizer
|
|
2
|
+
|
|
3
|
+
A lightweight Python library for cleaning and normalizing Arabic text, with no dependencies.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
```
|
|
7
|
+
pip install arabic-normalizer
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
- Remove diacritics (tashkeel) and tatweel
|
|
12
|
+
- Unify alef forms (أ إ آ → ا) and ى → ي
|
|
13
|
+
- Convert Arabic-Indic digits (٠١٢) to 0-9
|
|
14
|
+
- Optional ة → ه normalization
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
```python
|
|
18
|
+
from arabic_normalizer import normalize
|
|
19
|
+
|
|
20
|
+
normalize("أَهْلاً بِكُمْ فِي الرِّيَاضِ ٢٠٢٦")
|
|
21
|
+
# 'اهلا بكم في الرياض 2026'
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
MIT
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Lightweight Arabic text normalization."""
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
__version__ = "0.1.0"
|
|
5
|
+
|
|
6
|
+
_DIACRITICS = re.compile(r"[\u0617-\u061A\u064B-\u0652\u0670]")
|
|
7
|
+
_ALEF = re.compile(r"[إأآٱ]")
|
|
8
|
+
_DIGITS = str.maketrans("٠١٢٣٤٥٦٧٨٩۰۱۲۳۴۵۶۷۸۹", "01234567890123456789")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def remove_diacritics(text: str) -> str:
|
|
12
|
+
"""Remove tashkeel (fatha, damma, kasra, shadda, sukun...)."""
|
|
13
|
+
return _DIACRITICS.sub("", text)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def remove_tatweel(text: str) -> str:
|
|
17
|
+
"""Remove tatweel (ـ) used for stretching words."""
|
|
18
|
+
return text.replace("\u0640", "")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def normalize_alef(text: str) -> str:
|
|
22
|
+
"""Unify أ إ آ ٱ into ا."""
|
|
23
|
+
return _ALEF.sub("ا", text)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def normalize_yaa(text: str) -> str:
|
|
27
|
+
"""Convert ى to ي."""
|
|
28
|
+
return text.replace("ى", "ي")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def normalize_taa_marbuta(text: str) -> str:
|
|
32
|
+
"""Convert ة to ه."""
|
|
33
|
+
return text.replace("ة", "ه")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def convert_digits(text: str) -> str:
|
|
37
|
+
"""Convert Arabic-Indic and Persian digits to 0-9."""
|
|
38
|
+
return text.translate(_DIGITS)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def normalize(text: str, taa_marbuta: bool = False) -> str:
|
|
42
|
+
"""Apply all common normalization steps."""
|
|
43
|
+
text = remove_diacritics(text)
|
|
44
|
+
text = remove_tatweel(text)
|
|
45
|
+
text = normalize_alef(text)
|
|
46
|
+
text = normalize_yaa(text)
|
|
47
|
+
text = convert_digits(text)
|
|
48
|
+
if taa_marbuta:
|
|
49
|
+
text = normalize_taa_marbuta(text)
|
|
50
|
+
return " ".join(text.split())
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "arabic-normalizer"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Lightweight Arabic text normalization for search and NLP"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [{ name = "Abdulaziz Alkhayyal" }]
|
|
13
|
+
keywords = ["arabic", "nlp", "text", "normalization"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Natural Language :: Arabic",
|
|
17
|
+
"Topic :: Text Processing :: Linguistic",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://github.com/azizalkhayal-netizen/arabic-normalizer"
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from arabic_normalizer import (
|
|
2
|
+
convert_digits,
|
|
3
|
+
normalize,
|
|
4
|
+
normalize_alef,
|
|
5
|
+
normalize_taa_marbuta,
|
|
6
|
+
normalize_yaa,
|
|
7
|
+
remove_diacritics,
|
|
8
|
+
remove_tatweel,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_remove_diacritics():
|
|
13
|
+
assert remove_diacritics("مُحَمَّدٌ") == "محمد"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_remove_tatweel():
|
|
17
|
+
assert remove_tatweel("مـــرحبا") == "مرحبا"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_normalize_alef():
|
|
21
|
+
assert normalize_alef("أإآٱ") == "اااا"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_normalize_yaa():
|
|
25
|
+
assert normalize_yaa("مستشفى") == "مستشفي"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_normalize_taa_marbuta():
|
|
29
|
+
assert normalize_taa_marbuta("مدرسة") == "مدرسه"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_convert_digits():
|
|
33
|
+
assert convert_digits("٢٠٢٦ و ۱۴") == "2026 و 14"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_normalize_full():
|
|
37
|
+
assert normalize("أَهْلاً بِكُمْ فِي الرِّيَاضِ ٢٠٢٦") == "اهلا بكم في الرياض 2026"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_normalize_whitespace():
|
|
41
|
+
assert normalize(" مرحبا بكم ") == "مرحبا بكم"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_normalize_taa_option():
|
|
45
|
+
assert normalize("مدرسة", taa_marbuta=True) == "مدرسه"
|
|
46
|
+
assert normalize("مدرسة") == "مدرسة"
|