dxmohammad-nlp-toolkit 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.
- dxmohammad_nlp_toolkit-0.1.0/LICENSE +21 -0
- dxmohammad_nlp_toolkit-0.1.0/PKG-INFO +358 -0
- dxmohammad_nlp_toolkit-0.1.0/README.md +334 -0
- dxmohammad_nlp_toolkit-0.1.0/dxmohammad_nlp_toolkit.egg-info/PKG-INFO +358 -0
- dxmohammad_nlp_toolkit-0.1.0/dxmohammad_nlp_toolkit.egg-info/SOURCES.txt +34 -0
- dxmohammad_nlp_toolkit-0.1.0/dxmohammad_nlp_toolkit.egg-info/dependency_links.txt +1 -0
- dxmohammad_nlp_toolkit-0.1.0/dxmohammad_nlp_toolkit.egg-info/requires.txt +4 -0
- dxmohammad_nlp_toolkit-0.1.0/dxmohammad_nlp_toolkit.egg-info/top_level.txt +1 -0
- dxmohammad_nlp_toolkit-0.1.0/nlp_toolkit/__init__.py +0 -0
- dxmohammad_nlp_toolkit-0.1.0/nlp_toolkit/_nltk.py +24 -0
- dxmohammad_nlp_toolkit-0.1.0/nlp_toolkit/_spacy.py +14 -0
- dxmohammad_nlp_toolkit-0.1.0/nlp_toolkit/cleaning.py +50 -0
- dxmohammad_nlp_toolkit-0.1.0/nlp_toolkit/lemmatization.py +14 -0
- dxmohammad_nlp_toolkit-0.1.0/nlp_toolkit/ner.py +18 -0
- dxmohammad_nlp_toolkit-0.1.0/nlp_toolkit/nlp_pipeline.py +54 -0
- dxmohammad_nlp_toolkit-0.1.0/nlp_toolkit/normalization.py +29 -0
- dxmohammad_nlp_toolkit-0.1.0/nlp_toolkit/pos_tagging.py +15 -0
- dxmohammad_nlp_toolkit-0.1.0/nlp_toolkit/sentence_tokenization.py +14 -0
- dxmohammad_nlp_toolkit-0.1.0/nlp_toolkit/stemming.py +33 -0
- dxmohammad_nlp_toolkit-0.1.0/nlp_toolkit/stopwords.py +52 -0
- dxmohammad_nlp_toolkit-0.1.0/nlp_toolkit/tokenization.py +11 -0
- dxmohammad_nlp_toolkit-0.1.0/nlp_toolkit/vectorization.py +63 -0
- dxmohammad_nlp_toolkit-0.1.0/pyproject.toml +53 -0
- dxmohammad_nlp_toolkit-0.1.0/setup.cfg +4 -0
- dxmohammad_nlp_toolkit-0.1.0/tests/test_cleaning.py +69 -0
- dxmohammad_nlp_toolkit-0.1.0/tests/test_lemmatization.py +33 -0
- dxmohammad_nlp_toolkit-0.1.0/tests/test_ner.py +53 -0
- dxmohammad_nlp_toolkit-0.1.0/tests/test_nlp_pipeline.py +102 -0
- dxmohammad_nlp_toolkit-0.1.0/tests/test_nltk_resources.py +33 -0
- dxmohammad_nlp_toolkit-0.1.0/tests/test_normalization.py +56 -0
- dxmohammad_nlp_toolkit-0.1.0/tests/test_pos_tagging.py +36 -0
- dxmohammad_nlp_toolkit-0.1.0/tests/test_sentence_tokenization.py +35 -0
- dxmohammad_nlp_toolkit-0.1.0/tests/test_stemming.py +40 -0
- dxmohammad_nlp_toolkit-0.1.0/tests/test_stopwords.py +66 -0
- dxmohammad_nlp_toolkit-0.1.0/tests/test_tokenization.py +32 -0
- dxmohammad_nlp_toolkit-0.1.0/tests/test_vectorization.py +79 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dxmohammad
|
|
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,358 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dxmohammad-nlp-toolkit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A modular Python toolkit for text preprocessing, linguistic analysis, and text vectorization.
|
|
5
|
+
Author: Mohammad
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/dxmohammad/nlp-toolkit
|
|
8
|
+
Project-URL: Repository, https://github.com/dxmohammad/nlp-toolkit
|
|
9
|
+
Project-URL: Issues, https://github.com/dxmohammad/nlp-toolkit/issues
|
|
10
|
+
Keywords: nlp,natural-language-processing,text-processing,tokenization,lemmatization,stemming,text-vectorization
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: nltk>=3.8
|
|
20
|
+
Requires-Dist: spacy>=3.7
|
|
21
|
+
Requires-Dist: scikit-learn>=1.2
|
|
22
|
+
Requires-Dist: scipy>=1.10
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# NLP Toolkit
|
|
26
|
+
|
|
27
|
+
A Python toolkit for Natural Language Processing (NLP), providing reusable functions for common text preprocessing, linguistic analysis, and text vectorization tasks.
|
|
28
|
+
|
|
29
|
+
The project is designed with a modular structure, allowing developers to use individual NLP functions or combine them into a complete text-processing pipeline.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
The toolkit currently includes 11 modules:
|
|
34
|
+
|
|
35
|
+
| Module | Description |
|
|
36
|
+
|---|---|
|
|
37
|
+
| `cleaning` | Removes punctuation, numbers, and unnecessary characters |
|
|
38
|
+
| `normalization` | Normalizes text and whitespace |
|
|
39
|
+
| `tokenization` | Splits text into individual words |
|
|
40
|
+
| `stopwords` | Removes stopwords while preserving negation words |
|
|
41
|
+
| `stemming` | Applies Porter Stemming |
|
|
42
|
+
| `lemmatization` | Converts words into their base forms using spaCy |
|
|
43
|
+
| `pos_tagging` | Performs Part-of-Speech tagging |
|
|
44
|
+
| `ner` | Extracts Named Entities from text |
|
|
45
|
+
| `sentence_tokenization` | Splits text into sentences |
|
|
46
|
+
| `vectorization` | Supports Bag of Words and TF-IDF |
|
|
47
|
+
| `nlp_pipeline` | Combines multiple NLP operations into one pipeline |
|
|
48
|
+
|
|
49
|
+
## Project Structure
|
|
50
|
+
|
|
51
|
+
```text
|
|
52
|
+
nlp-toolkit/
|
|
53
|
+
│
|
|
54
|
+
├── nlp_toolkit/
|
|
55
|
+
│ ├── __init__.py
|
|
56
|
+
│ ├── _nltk.py
|
|
57
|
+
│ ├── _spacy.py
|
|
58
|
+
│ ├── cleaning.py
|
|
59
|
+
│ ├── normalization.py
|
|
60
|
+
│ ├── tokenization.py
|
|
61
|
+
│ ├── stopwords.py
|
|
62
|
+
│ ├── stemming.py
|
|
63
|
+
│ ├── lemmatization.py
|
|
64
|
+
│ ├── pos_tagging.py
|
|
65
|
+
│ ├── ner.py
|
|
66
|
+
│ ├── sentence_tokenization.py
|
|
67
|
+
│ ├── vectorization.py
|
|
68
|
+
│ └── nlp_pipeline.py
|
|
69
|
+
│
|
|
70
|
+
├── tests/
|
|
71
|
+
│ ├── test_cleaning.py
|
|
72
|
+
│ ├── test_lemmatization.py
|
|
73
|
+
│ ├── test_ner.py
|
|
74
|
+
│ ├── test_nlp_pipeline.py
|
|
75
|
+
│ ├── test_nltk_resources.py
|
|
76
|
+
│ ├── test_normalization.py
|
|
77
|
+
│ ├── test_pos_tagging.py
|
|
78
|
+
│ ├── test_sentence_tokenization.py
|
|
79
|
+
│ ├── test_stemming.py
|
|
80
|
+
│ ├── test_stopwords.py
|
|
81
|
+
│ ├── test_tokenization.py
|
|
82
|
+
│ └── test_vectorization.py
|
|
83
|
+
│
|
|
84
|
+
├── .gitignore
|
|
85
|
+
├── LICENSE
|
|
86
|
+
├── README.md
|
|
87
|
+
├── pyproject.toml
|
|
88
|
+
└── requirements.txt
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Requirements
|
|
92
|
+
|
|
93
|
+
- Python 3.10 or later.
|
|
94
|
+
- NLTK
|
|
95
|
+
- spaCy
|
|
96
|
+
- scikit-learn
|
|
97
|
+
- SciPy
|
|
98
|
+
|
|
99
|
+
## Installation
|
|
100
|
+
|
|
101
|
+
### 1. Clone the repository
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
git clone https://github.com/dxmohammad/nlp-toolkit.git
|
|
105
|
+
cd nlp-toolkit
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 2. Install the package
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
pip install .
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
This installs the toolkit and its required Python dependencies.
|
|
115
|
+
|
|
116
|
+
### 3. Download the spaCy English model
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
python -m spacy download en_core_web_sm
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### 4. Download NLTK resources
|
|
123
|
+
|
|
124
|
+
Some modules require additional NLTK language resources.
|
|
125
|
+
|
|
126
|
+
Download the required resources using:
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
import nltk
|
|
130
|
+
|
|
131
|
+
nltk.download("punkt_tab")
|
|
132
|
+
nltk.download("stopwords")
|
|
133
|
+
nltk.download("averaged_perceptron_tagger_eng")
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
These resources are required by the relevant tokenization, stopword removal, and POS tagging modules.
|
|
137
|
+
|
|
138
|
+
## Usage
|
|
139
|
+
|
|
140
|
+
### 1. Text Cleaning
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from nlp_toolkit.cleaning import clean_text
|
|
144
|
+
|
|
145
|
+
text = "Hello, World! NLP is interesting."
|
|
146
|
+
result = clean_text(text)
|
|
147
|
+
|
|
148
|
+
print(result)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### 2. Text Normalization
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
from nlp_toolkit.normalization import normalize_text
|
|
155
|
+
|
|
156
|
+
text = " HELLO WORLD "
|
|
157
|
+
result = normalize_text(text)
|
|
158
|
+
|
|
159
|
+
print(result)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### 3. Word Tokenization
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
from nlp_toolkit.tokenization import tokenize_text
|
|
166
|
+
|
|
167
|
+
text = "I love Natural Language Processing."
|
|
168
|
+
tokens = tokenize_text(text)
|
|
169
|
+
|
|
170
|
+
print(tokens)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### 4. Stopword Removal
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
from nlp_toolkit.stopwords import remove_stopwords
|
|
177
|
+
|
|
178
|
+
text = "This is an example of text processing."
|
|
179
|
+
result = remove_stopwords(text)
|
|
180
|
+
|
|
181
|
+
print(result)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### 5. Stemming
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from nlp_toolkit.stemming import stem_words
|
|
188
|
+
|
|
189
|
+
words = ["playing", "studies", "running"]
|
|
190
|
+
result = stem_words(words)
|
|
191
|
+
|
|
192
|
+
print(result)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### 6. Lemmatization
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
from nlp_toolkit.lemmatization import lemmatize_text
|
|
199
|
+
|
|
200
|
+
text = "The children are playing."
|
|
201
|
+
result = lemmatize_text(text)
|
|
202
|
+
|
|
203
|
+
print(result)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### 7. Part-of-Speech Tagging
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
from nlp_toolkit.pos_tagging import get_pos_tags
|
|
210
|
+
|
|
211
|
+
text = "The researchers develop intelligent systems."
|
|
212
|
+
result = get_pos_tags(text)
|
|
213
|
+
|
|
214
|
+
print(result)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### 8. Named Entity Recognition
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
from nlp_toolkit.ner import extract_entities
|
|
221
|
+
|
|
222
|
+
text = "Elon Musk founded SpaceX."
|
|
223
|
+
result = extract_entities(text)
|
|
224
|
+
|
|
225
|
+
print(result)
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### 9. Sentence Tokenization
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
from nlp_toolkit.sentence_tokenization import tokenize_sentences
|
|
232
|
+
|
|
233
|
+
text = "NLP is interesting. Python is useful."
|
|
234
|
+
result = tokenize_sentences(text)
|
|
235
|
+
|
|
236
|
+
print(result)
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### 10. Text Vectorization
|
|
240
|
+
|
|
241
|
+
**Bag of Words**
|
|
242
|
+
|
|
243
|
+
```python
|
|
244
|
+
from nlp_toolkit.vectorization import bag_of_words
|
|
245
|
+
|
|
246
|
+
documents = [
|
|
247
|
+
"I love machine learning",
|
|
248
|
+
"Machine learning is interesting"
|
|
249
|
+
]
|
|
250
|
+
|
|
251
|
+
matrix, vocabulary = bag_of_words(documents)
|
|
252
|
+
|
|
253
|
+
print(matrix.toarray())
|
|
254
|
+
print(vocabulary)
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
**TF-IDF**
|
|
258
|
+
|
|
259
|
+
```python
|
|
260
|
+
from nlp_toolkit.vectorization import tfidf_vectorization
|
|
261
|
+
|
|
262
|
+
documents = [
|
|
263
|
+
"I love machine learning",
|
|
264
|
+
"Machine learning is interesting"
|
|
265
|
+
]
|
|
266
|
+
|
|
267
|
+
matrix, vocabulary = tfidf_vectorization(documents)
|
|
268
|
+
|
|
269
|
+
print(matrix.toarray())
|
|
270
|
+
print(vocabulary)
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### 11. Complete NLP Pipeline
|
|
274
|
+
|
|
275
|
+
```python
|
|
276
|
+
from nlp_toolkit.nlp_pipeline import process_text
|
|
277
|
+
|
|
278
|
+
text = "Elon Musk is developing artificial intelligence."
|
|
279
|
+
|
|
280
|
+
result = process_text(text)
|
|
281
|
+
|
|
282
|
+
for key, value in result.items():
|
|
283
|
+
print(f"{key}: {value}")
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## Testing
|
|
287
|
+
|
|
288
|
+
The project includes 12 individual test files.
|
|
289
|
+
|
|
290
|
+
To run all tests from the project root directory using PowerShell:
|
|
291
|
+
|
|
292
|
+
```powershell
|
|
293
|
+
$python = "python"
|
|
294
|
+
$env:PYTHONPATH = (Get-Location).Path
|
|
295
|
+
|
|
296
|
+
try {
|
|
297
|
+
$testFiles = Get-ChildItem .\tests -Filter "test_*.py" -File | Sort-Object Name
|
|
298
|
+
|
|
299
|
+
foreach ($test in $testFiles) {
|
|
300
|
+
Write-Host "Testing $($test.Name)"
|
|
301
|
+
|
|
302
|
+
& $python $test.FullName
|
|
303
|
+
|
|
304
|
+
if ($LASTEXITCODE -ne 0) {
|
|
305
|
+
throw "Test failed: $($test.Name)"
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
Write-Host "ALL PROJECT TESTS PASSED!"
|
|
310
|
+
}
|
|
311
|
+
finally {
|
|
312
|
+
Remove-Item Env:PYTHONPATH -ErrorAction SilentlyContinue
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## Technologies Used
|
|
317
|
+
|
|
318
|
+
- Python
|
|
319
|
+
- NLTK
|
|
320
|
+
- spaCy
|
|
321
|
+
- scikit-learn
|
|
322
|
+
- SciPy
|
|
323
|
+
|
|
324
|
+
## Project Status
|
|
325
|
+
|
|
326
|
+
The initial implementation of the toolkit is complete.
|
|
327
|
+
|
|
328
|
+
The project has been organized as an installable Python package, with:
|
|
329
|
+
|
|
330
|
+
- 11 functional NLP modules.
|
|
331
|
+
- 12 individual test files.
|
|
332
|
+
- Modular NLTK resource management.
|
|
333
|
+
- Cached spaCy model loading.
|
|
334
|
+
- Package configuration using `pyproject.toml`.
|
|
335
|
+
- Wheel and source distribution builds.
|
|
336
|
+
- Successful local installation testing in an independent Python environment.
|
|
337
|
+
|
|
338
|
+
The package has not yet been published on PyPI.
|
|
339
|
+
|
|
340
|
+
## Future Improvements
|
|
341
|
+
|
|
342
|
+
- Expand language support.
|
|
343
|
+
- Add more text preprocessing techniques.
|
|
344
|
+
- Improve pipeline flexibility.
|
|
345
|
+
- Expand automated test coverage.
|
|
346
|
+
- Publish the package on PyPI.
|
|
347
|
+
|
|
348
|
+
## License
|
|
349
|
+
|
|
350
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
351
|
+
|
|
352
|
+
## Author
|
|
353
|
+
|
|
354
|
+
**Mohammad**
|
|
355
|
+
|
|
356
|
+
GitHub: [@dxmohammad](https://github.com/dxmohammad)
|
|
357
|
+
|
|
358
|
+
Project Repository: [nlp-toolkit](https://github.com/dxmohammad/nlp-toolkit)
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
# NLP Toolkit
|
|
2
|
+
|
|
3
|
+
A Python toolkit for Natural Language Processing (NLP), providing reusable functions for common text preprocessing, linguistic analysis, and text vectorization tasks.
|
|
4
|
+
|
|
5
|
+
The project is designed with a modular structure, allowing developers to use individual NLP functions or combine them into a complete text-processing pipeline.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
The toolkit currently includes 11 modules:
|
|
10
|
+
|
|
11
|
+
| Module | Description |
|
|
12
|
+
|---|---|
|
|
13
|
+
| `cleaning` | Removes punctuation, numbers, and unnecessary characters |
|
|
14
|
+
| `normalization` | Normalizes text and whitespace |
|
|
15
|
+
| `tokenization` | Splits text into individual words |
|
|
16
|
+
| `stopwords` | Removes stopwords while preserving negation words |
|
|
17
|
+
| `stemming` | Applies Porter Stemming |
|
|
18
|
+
| `lemmatization` | Converts words into their base forms using spaCy |
|
|
19
|
+
| `pos_tagging` | Performs Part-of-Speech tagging |
|
|
20
|
+
| `ner` | Extracts Named Entities from text |
|
|
21
|
+
| `sentence_tokenization` | Splits text into sentences |
|
|
22
|
+
| `vectorization` | Supports Bag of Words and TF-IDF |
|
|
23
|
+
| `nlp_pipeline` | Combines multiple NLP operations into one pipeline |
|
|
24
|
+
|
|
25
|
+
## Project Structure
|
|
26
|
+
|
|
27
|
+
```text
|
|
28
|
+
nlp-toolkit/
|
|
29
|
+
│
|
|
30
|
+
├── nlp_toolkit/
|
|
31
|
+
│ ├── __init__.py
|
|
32
|
+
│ ├── _nltk.py
|
|
33
|
+
│ ├── _spacy.py
|
|
34
|
+
│ ├── cleaning.py
|
|
35
|
+
│ ├── normalization.py
|
|
36
|
+
│ ├── tokenization.py
|
|
37
|
+
│ ├── stopwords.py
|
|
38
|
+
│ ├── stemming.py
|
|
39
|
+
│ ├── lemmatization.py
|
|
40
|
+
│ ├── pos_tagging.py
|
|
41
|
+
│ ├── ner.py
|
|
42
|
+
│ ├── sentence_tokenization.py
|
|
43
|
+
│ ├── vectorization.py
|
|
44
|
+
│ └── nlp_pipeline.py
|
|
45
|
+
│
|
|
46
|
+
├── tests/
|
|
47
|
+
│ ├── test_cleaning.py
|
|
48
|
+
│ ├── test_lemmatization.py
|
|
49
|
+
│ ├── test_ner.py
|
|
50
|
+
│ ├── test_nlp_pipeline.py
|
|
51
|
+
│ ├── test_nltk_resources.py
|
|
52
|
+
│ ├── test_normalization.py
|
|
53
|
+
│ ├── test_pos_tagging.py
|
|
54
|
+
│ ├── test_sentence_tokenization.py
|
|
55
|
+
│ ├── test_stemming.py
|
|
56
|
+
│ ├── test_stopwords.py
|
|
57
|
+
│ ├── test_tokenization.py
|
|
58
|
+
│ └── test_vectorization.py
|
|
59
|
+
│
|
|
60
|
+
├── .gitignore
|
|
61
|
+
├── LICENSE
|
|
62
|
+
├── README.md
|
|
63
|
+
├── pyproject.toml
|
|
64
|
+
└── requirements.txt
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Requirements
|
|
68
|
+
|
|
69
|
+
- Python 3.10 or later.
|
|
70
|
+
- NLTK
|
|
71
|
+
- spaCy
|
|
72
|
+
- scikit-learn
|
|
73
|
+
- SciPy
|
|
74
|
+
|
|
75
|
+
## Installation
|
|
76
|
+
|
|
77
|
+
### 1. Clone the repository
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
git clone https://github.com/dxmohammad/nlp-toolkit.git
|
|
81
|
+
cd nlp-toolkit
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 2. Install the package
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
pip install .
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
This installs the toolkit and its required Python dependencies.
|
|
91
|
+
|
|
92
|
+
### 3. Download the spaCy English model
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
python -m spacy download en_core_web_sm
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 4. Download NLTK resources
|
|
99
|
+
|
|
100
|
+
Some modules require additional NLTK language resources.
|
|
101
|
+
|
|
102
|
+
Download the required resources using:
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
import nltk
|
|
106
|
+
|
|
107
|
+
nltk.download("punkt_tab")
|
|
108
|
+
nltk.download("stopwords")
|
|
109
|
+
nltk.download("averaged_perceptron_tagger_eng")
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
These resources are required by the relevant tokenization, stopword removal, and POS tagging modules.
|
|
113
|
+
|
|
114
|
+
## Usage
|
|
115
|
+
|
|
116
|
+
### 1. Text Cleaning
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from nlp_toolkit.cleaning import clean_text
|
|
120
|
+
|
|
121
|
+
text = "Hello, World! NLP is interesting."
|
|
122
|
+
result = clean_text(text)
|
|
123
|
+
|
|
124
|
+
print(result)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 2. Text Normalization
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from nlp_toolkit.normalization import normalize_text
|
|
131
|
+
|
|
132
|
+
text = " HELLO WORLD "
|
|
133
|
+
result = normalize_text(text)
|
|
134
|
+
|
|
135
|
+
print(result)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### 3. Word Tokenization
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from nlp_toolkit.tokenization import tokenize_text
|
|
142
|
+
|
|
143
|
+
text = "I love Natural Language Processing."
|
|
144
|
+
tokens = tokenize_text(text)
|
|
145
|
+
|
|
146
|
+
print(tokens)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### 4. Stopword Removal
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from nlp_toolkit.stopwords import remove_stopwords
|
|
153
|
+
|
|
154
|
+
text = "This is an example of text processing."
|
|
155
|
+
result = remove_stopwords(text)
|
|
156
|
+
|
|
157
|
+
print(result)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### 5. Stemming
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from nlp_toolkit.stemming import stem_words
|
|
164
|
+
|
|
165
|
+
words = ["playing", "studies", "running"]
|
|
166
|
+
result = stem_words(words)
|
|
167
|
+
|
|
168
|
+
print(result)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### 6. Lemmatization
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
from nlp_toolkit.lemmatization import lemmatize_text
|
|
175
|
+
|
|
176
|
+
text = "The children are playing."
|
|
177
|
+
result = lemmatize_text(text)
|
|
178
|
+
|
|
179
|
+
print(result)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### 7. Part-of-Speech Tagging
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
from nlp_toolkit.pos_tagging import get_pos_tags
|
|
186
|
+
|
|
187
|
+
text = "The researchers develop intelligent systems."
|
|
188
|
+
result = get_pos_tags(text)
|
|
189
|
+
|
|
190
|
+
print(result)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### 8. Named Entity Recognition
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
from nlp_toolkit.ner import extract_entities
|
|
197
|
+
|
|
198
|
+
text = "Elon Musk founded SpaceX."
|
|
199
|
+
result = extract_entities(text)
|
|
200
|
+
|
|
201
|
+
print(result)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### 9. Sentence Tokenization
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
from nlp_toolkit.sentence_tokenization import tokenize_sentences
|
|
208
|
+
|
|
209
|
+
text = "NLP is interesting. Python is useful."
|
|
210
|
+
result = tokenize_sentences(text)
|
|
211
|
+
|
|
212
|
+
print(result)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### 10. Text Vectorization
|
|
216
|
+
|
|
217
|
+
**Bag of Words**
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
from nlp_toolkit.vectorization import bag_of_words
|
|
221
|
+
|
|
222
|
+
documents = [
|
|
223
|
+
"I love machine learning",
|
|
224
|
+
"Machine learning is interesting"
|
|
225
|
+
]
|
|
226
|
+
|
|
227
|
+
matrix, vocabulary = bag_of_words(documents)
|
|
228
|
+
|
|
229
|
+
print(matrix.toarray())
|
|
230
|
+
print(vocabulary)
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
**TF-IDF**
|
|
234
|
+
|
|
235
|
+
```python
|
|
236
|
+
from nlp_toolkit.vectorization import tfidf_vectorization
|
|
237
|
+
|
|
238
|
+
documents = [
|
|
239
|
+
"I love machine learning",
|
|
240
|
+
"Machine learning is interesting"
|
|
241
|
+
]
|
|
242
|
+
|
|
243
|
+
matrix, vocabulary = tfidf_vectorization(documents)
|
|
244
|
+
|
|
245
|
+
print(matrix.toarray())
|
|
246
|
+
print(vocabulary)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### 11. Complete NLP Pipeline
|
|
250
|
+
|
|
251
|
+
```python
|
|
252
|
+
from nlp_toolkit.nlp_pipeline import process_text
|
|
253
|
+
|
|
254
|
+
text = "Elon Musk is developing artificial intelligence."
|
|
255
|
+
|
|
256
|
+
result = process_text(text)
|
|
257
|
+
|
|
258
|
+
for key, value in result.items():
|
|
259
|
+
print(f"{key}: {value}")
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Testing
|
|
263
|
+
|
|
264
|
+
The project includes 12 individual test files.
|
|
265
|
+
|
|
266
|
+
To run all tests from the project root directory using PowerShell:
|
|
267
|
+
|
|
268
|
+
```powershell
|
|
269
|
+
$python = "python"
|
|
270
|
+
$env:PYTHONPATH = (Get-Location).Path
|
|
271
|
+
|
|
272
|
+
try {
|
|
273
|
+
$testFiles = Get-ChildItem .\tests -Filter "test_*.py" -File | Sort-Object Name
|
|
274
|
+
|
|
275
|
+
foreach ($test in $testFiles) {
|
|
276
|
+
Write-Host "Testing $($test.Name)"
|
|
277
|
+
|
|
278
|
+
& $python $test.FullName
|
|
279
|
+
|
|
280
|
+
if ($LASTEXITCODE -ne 0) {
|
|
281
|
+
throw "Test failed: $($test.Name)"
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
Write-Host "ALL PROJECT TESTS PASSED!"
|
|
286
|
+
}
|
|
287
|
+
finally {
|
|
288
|
+
Remove-Item Env:PYTHONPATH -ErrorAction SilentlyContinue
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Technologies Used
|
|
293
|
+
|
|
294
|
+
- Python
|
|
295
|
+
- NLTK
|
|
296
|
+
- spaCy
|
|
297
|
+
- scikit-learn
|
|
298
|
+
- SciPy
|
|
299
|
+
|
|
300
|
+
## Project Status
|
|
301
|
+
|
|
302
|
+
The initial implementation of the toolkit is complete.
|
|
303
|
+
|
|
304
|
+
The project has been organized as an installable Python package, with:
|
|
305
|
+
|
|
306
|
+
- 11 functional NLP modules.
|
|
307
|
+
- 12 individual test files.
|
|
308
|
+
- Modular NLTK resource management.
|
|
309
|
+
- Cached spaCy model loading.
|
|
310
|
+
- Package configuration using `pyproject.toml`.
|
|
311
|
+
- Wheel and source distribution builds.
|
|
312
|
+
- Successful local installation testing in an independent Python environment.
|
|
313
|
+
|
|
314
|
+
The package has not yet been published on PyPI.
|
|
315
|
+
|
|
316
|
+
## Future Improvements
|
|
317
|
+
|
|
318
|
+
- Expand language support.
|
|
319
|
+
- Add more text preprocessing techniques.
|
|
320
|
+
- Improve pipeline flexibility.
|
|
321
|
+
- Expand automated test coverage.
|
|
322
|
+
- Publish the package on PyPI.
|
|
323
|
+
|
|
324
|
+
## License
|
|
325
|
+
|
|
326
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
327
|
+
|
|
328
|
+
## Author
|
|
329
|
+
|
|
330
|
+
**Mohammad**
|
|
331
|
+
|
|
332
|
+
GitHub: [@dxmohammad](https://github.com/dxmohammad)
|
|
333
|
+
|
|
334
|
+
Project Repository: [nlp-toolkit](https://github.com/dxmohammad/nlp-toolkit)
|