pytextprep-hm25 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.
- pytextprep_hm25-0.1.0/LICENSE +21 -0
- pytextprep_hm25-0.1.0/PKG-INFO +398 -0
- pytextprep_hm25-0.1.0/README.md +368 -0
- pytextprep_hm25-0.1.0/pyproject.toml +18 -0
- pytextprep_hm25-0.1.0/pytextprep/__init__.py +36 -0
- pytextprep_hm25-0.1.0/pytextprep/cleaner.py +25 -0
- pytextprep_hm25-0.1.0/pytextprep/examples/example1_functional.py +9 -0
- pytextprep_hm25-0.1.0/pytextprep/examples/example2_pipeline.py +16 -0
- pytextprep_hm25-0.1.0/pytextprep/examples/example3_arabic.py +6 -0
- pytextprep_hm25-0.1.0/pytextprep/exceptions.py +9 -0
- pytextprep_hm25-0.1.0/pytextprep/pipeline.py +79 -0
- pytextprep_hm25-0.1.0/pytextprep/registry.py +30 -0
- pytextprep_hm25-0.1.0/pytextprep/resources/contractions_en.tsv +55 -0
- pytextprep_hm25-0.1.0/pytextprep/resources/stopwords_en.txt +318 -0
- pytextprep_hm25-0.1.0/pytextprep/steps/accents.py +22 -0
- pytextprep_hm25-0.1.0/pytextprep/steps/cleaning.py +205 -0
- pytextprep_hm25-0.1.0/pytextprep/steps/filtering.py +78 -0
- pytextprep_hm25-0.1.0/pytextprep/steps/generate_ngrams.py +55 -0
- pytextprep_hm25-0.1.0/pytextprep/steps/lemmatizer.py +137 -0
- pytextprep_hm25-0.1.0/pytextprep/steps/normalize_arabic.py +47 -0
- pytextprep_hm25-0.1.0/pytextprep/steps/slang.py +94 -0
- pytextprep_hm25-0.1.0/pytextprep/steps/tokenize.py +39 -0
- pytextprep_hm25-0.1.0/pytextprep_hm25.egg-info/PKG-INFO +398 -0
- pytextprep_hm25-0.1.0/pytextprep_hm25.egg-info/SOURCES.txt +37 -0
- pytextprep_hm25-0.1.0/pytextprep_hm25.egg-info/dependency_links.txt +1 -0
- pytextprep_hm25-0.1.0/pytextprep_hm25.egg-info/top_level.txt +1 -0
- pytextprep_hm25-0.1.0/setup.cfg +4 -0
- pytextprep_hm25-0.1.0/tests/test_accents.py +19 -0
- pytextprep_hm25-0.1.0/tests/test_cleaner.py +37 -0
- pytextprep_hm25-0.1.0/tests/test_cleaning.py +119 -0
- pytextprep_hm25-0.1.0/tests/test_filtering.py +38 -0
- pytextprep_hm25-0.1.0/tests/test_integration.py +65 -0
- pytextprep_hm25-0.1.0/tests/test_lemmatizer.py +23 -0
- pytextprep_hm25-0.1.0/tests/test_ngrams.py +40 -0
- pytextprep_hm25-0.1.0/tests/test_normalize_arabic.py +32 -0
- pytextprep_hm25-0.1.0/tests/test_pipeline.py +96 -0
- pytextprep_hm25-0.1.0/tests/test_public_api.py +49 -0
- pytextprep_hm25-0.1.0/tests/test_slang.py +20 -0
- pytextprep_hm25-0.1.0/tests/test_tokenize.py +43 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Haneen Elbasiony
|
|
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,398 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pytextprep-hm25
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A pure Python text preprocessing library
|
|
5
|
+
License: MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2026 Haneen Elbasiony
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# Overview
|
|
33
|
+
PyTextPrep
|
|
34
|
+
An open-source Python library that cleans raw text for Natural Language Processing.It has zero runtime dependencies.The library does not rely on ready-made external NLP packages or tools such as:
|
|
35
|
+
NLTK,
|
|
36
|
+
spaCy,
|
|
37
|
+
emoji.
|
|
38
|
+
Instead, text-processing operations are implemented using Python's built-in features, regular expressions, Unicode handling, and the library's own resources and rules.This makes PyTextPrep lightweight and independent of external runtime packages.It offers two ways to work: call one cleaning function at a time, or describe a whole cleaning recipe once as a Pipeline and run it on any number of texts.
|
|
39
|
+
|
|
40
|
+
PyTextPrep offers three ways to work:
|
|
41
|
+
- Call one preprocessing function at a time.
|
|
42
|
+
- Configure a Pipeline and run it on one or more texts.
|
|
43
|
+
- Use the object-oriented TextCleaner interface to access registered steps as methods.
|
|
44
|
+
|
|
45
|
+
# Install from GitHub
|
|
46
|
+
|
|
47
|
+
Clone the repository:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
git clone https://github.com/HaneenMohamed25/pytextprep-project.git
|
|
51
|
+
cd pytextprep-project
|
|
52
|
+
```
|
|
53
|
+
Install in editable mode:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
python -m pip install -e .
|
|
57
|
+
```
|
|
58
|
+
# Install using pip
|
|
59
|
+
PyTextPrep is available on PyPI.
|
|
60
|
+
Install it using pip:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install pytextprep-hm25
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
# Requirements:
|
|
67
|
+
|
|
68
|
+
* Python 3.10 or higher.
|
|
69
|
+
* No external runtime dependencies are required.
|
|
70
|
+
|
|
71
|
+
# Running Tests
|
|
72
|
+
Rub all tests
|
|
73
|
+
```bash
|
|
74
|
+
python -m unittest discover -s tests -v
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### General Example
|
|
78
|
+
```text
|
|
79
|
+
In : "I don't like spam emails! Visit https://test.com right NOW."
|
|
80
|
+
Out: "not like spam email visit right"
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# pytextprep-project structure
|
|
85
|
+
```text
|
|
86
|
+
pytextprep-project/
|
|
87
|
+
├── pytextprep/
|
|
88
|
+
│ ├── __init__.py
|
|
89
|
+
│ ├── cleaner.py
|
|
90
|
+
│ ├── registry.py
|
|
91
|
+
│ ├── pipeline.py
|
|
92
|
+
│ ├── exceptions.py
|
|
93
|
+
│ ├── steps/
|
|
94
|
+
│ │ ├── __init__.py
|
|
95
|
+
│ │ ├── cleaning.py
|
|
96
|
+
│ │ ├── tokenize.py
|
|
97
|
+
│ │ ├── filtering.py
|
|
98
|
+
│ │ ├── slang.py
|
|
99
|
+
│ │ ├── generate_ngrams.py
|
|
100
|
+
│ │ ├── accents.py
|
|
101
|
+
│ │ ├── normalize_arabic.py
|
|
102
|
+
│ │ └── lemmatizer.py
|
|
103
|
+
│ ├── resources/
|
|
104
|
+
│ │ ├── stopwords_en.txt
|
|
105
|
+
│ │ └── contractions_en.tsv
|
|
106
|
+
│ └── examples/
|
|
107
|
+
│ ├── example1_functional.py
|
|
108
|
+
│ ├── example2_pipeline.py
|
|
109
|
+
│ └── example3_arabic.py
|
|
110
|
+
├── tests/
|
|
111
|
+
│ ├── test_cleaning.py
|
|
112
|
+
│ ├── test_tokenize.py
|
|
113
|
+
│ ├── test_filtering.py
|
|
114
|
+
│ ├── test_slang.py
|
|
115
|
+
│ ├── test_generate_ngrams.py
|
|
116
|
+
│ ├── test_accents.py
|
|
117
|
+
│ ├── test_normalize_arabic.py
|
|
118
|
+
│ ├── test_lemmatizer.py
|
|
119
|
+
│ ├── test_pipeline.py
|
|
120
|
+
│ ├── test_cleaner.py
|
|
121
|
+
│ ├── test_public_api.py
|
|
122
|
+
│ └── test_integration.py
|
|
123
|
+
├── pyproject.toml
|
|
124
|
+
├── README.md
|
|
125
|
+
├── LICENSE
|
|
126
|
+
└── .gitignore
|
|
127
|
+
```
|
|
128
|
+
- `registry.py`: Registers and manages preprocessing steps.
|
|
129
|
+
- `cleaner.py `: Provides an object-oriented interface to registered preprocessing steps.
|
|
130
|
+
- `pipeline.py`: Validates and executes pipeline configurations.
|
|
131
|
+
- `exceptions.py`: Defines custom library exceptions.
|
|
132
|
+
- `steps/`: Contains individual text-processing functions.
|
|
133
|
+
- `resources/`: Contains built-in language resources.
|
|
134
|
+
|
|
135
|
+
### Example 1: Functional API
|
|
136
|
+
|
|
137
|
+
Every registered step can also be imported and called as a regular Python function.
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from pytextprep import (
|
|
141
|
+
remove_urls,
|
|
142
|
+
remove_punctuation,
|
|
143
|
+
normalize_repeating_chars,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
raw_input = " Check out <https://example.com>!! I looove NLP #2026 😊... "
|
|
147
|
+
|
|
148
|
+
step1 = remove_urls(raw_input)
|
|
149
|
+
step2 = remove_punctuation(step1)
|
|
150
|
+
step3 = normalize_repeating_chars(step2)
|
|
151
|
+
|
|
152
|
+
print(step3)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Output:
|
|
156
|
+
|
|
157
|
+
```text
|
|
158
|
+
Check out I love NLP 2026 😊
|
|
159
|
+
```
|
|
160
|
+
### Example 2: Pipeline API
|
|
161
|
+
|
|
162
|
+
The Pipeline API allows you to combine multiple preprocessing steps and execute them in sequence.
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
from pytextprep import Pipeline
|
|
166
|
+
|
|
167
|
+
nlp_pipeline = Pipeline([
|
|
168
|
+
("remove_urls", {}),
|
|
169
|
+
("expand_contractions", {}),
|
|
170
|
+
("remove_punctuation", {"keep_emojis": False}),
|
|
171
|
+
("remove_stopwords", {"custom_words": ["check"]}),
|
|
172
|
+
("lowercase", {}),
|
|
173
|
+
("lemmatize", {}),
|
|
174
|
+
])
|
|
175
|
+
|
|
176
|
+
raw_text = "I don't like spam emails! Visit https://test.com right NOW."
|
|
177
|
+
|
|
178
|
+
processed_text = nlp_pipeline.transform(raw_text)
|
|
179
|
+
|
|
180
|
+
print("Raw: ", raw_text)
|
|
181
|
+
print("Processed:", processed_text)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Output:
|
|
185
|
+
|
|
186
|
+
```text
|
|
187
|
+
Raw: I don't like spam emails! Visit https://test.com right NOW.
|
|
188
|
+
Processed: not like spam email visit right
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Batch Processing
|
|
192
|
+
Use transform_batch() to apply the same pipeline to multiple strings:
|
|
193
|
+
```bash
|
|
194
|
+
from pytextprep import Pipeline
|
|
195
|
+
|
|
196
|
+
pipeline = Pipeline([
|
|
197
|
+
("lowercase", {}),
|
|
198
|
+
("remove_urls", {}),
|
|
199
|
+
])
|
|
200
|
+
|
|
201
|
+
texts = ["HELLO PYTHON", "Visit https://google.com"]
|
|
202
|
+
results = pipeline.transform_batch(texts)
|
|
203
|
+
|
|
204
|
+
print(results)
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Example 3: TextCleaner API
|
|
208
|
+
TextCleaner provides an object-oriented interface for accessing registered preprocessing steps as methods.
|
|
209
|
+
```python
|
|
210
|
+
from pytextprep import TextCleaner
|
|
211
|
+
|
|
212
|
+
cleaner = TextCleaner()
|
|
213
|
+
|
|
214
|
+
text = "HELLO PYTHON! Visit https://google.com"
|
|
215
|
+
text = cleaner.remove_urls(text)
|
|
216
|
+
text = cleaner.lowercase(text)
|
|
217
|
+
|
|
218
|
+
print(text)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Output:
|
|
222
|
+
```text
|
|
223
|
+
hello python! visit
|
|
224
|
+
```
|
|
225
|
+
The constructor accepts a language argument:
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
cleaner = TextCleaner(language="en")
|
|
229
|
+
```
|
|
230
|
+
The built-in stopword resource currently focuses on English.
|
|
231
|
+
|
|
232
|
+
### Example 4: Arabic Text
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
from pytextprep import Pipeline
|
|
236
|
+
|
|
237
|
+
arabic = Pipeline([
|
|
238
|
+
("normalize_arabic", {}),
|
|
239
|
+
("remove_punctuation", {}),
|
|
240
|
+
])
|
|
241
|
+
|
|
242
|
+
print(arabic.transform("أَهْلاً بِكُم في الـــمـعهد!!"))
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Output:
|
|
246
|
+
|
|
247
|
+
```text
|
|
248
|
+
اهلا بكم في المعهد
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Functions
|
|
252
|
+
|
|
253
|
+
### 1. Text Cleaning and Normalization
|
|
254
|
+
|
|
255
|
+
| Function | What It Does | Parameters (Required / Optional) | Example and Output |
|
|
256
|
+
|---|---|---|---|
|
|
257
|
+
| `lowercase` | Converts all characters to lowercase using `casefold()`. | `text` — Required | `lowercase("HELLO Python")` → `"hello python"` |
|
|
258
|
+
| `normalize_whitespace` | Removes extra spaces, tabs, and line breaks, leaving single spaces between words. | `text` — Required | `normalize_whitespace("hello world")` → `"hello world"` |
|
|
259
|
+
| `remove_urls` | Removes URLs from the text. | `text` — Required; `replace_with=""` — Optional, replacement for each URL. | `remove_urls("Visit https://test.com")` → `"Visit"` |
|
|
260
|
+
| `remove_emails` | Removes email addresses from the text. | `text` — Required; `replace_with=""` — Optional, replacement for each email. | `remove_emails("Contact test@gmail.com")` → `"Contact"` |
|
|
261
|
+
| `remove_punctuation` | Removes punctuation marks while keeping emojis by default. | `text` — Required; `keep_emojis=True` — Optional, controls whether emojis are kept. | `remove_punctuation("Hello!", keep_emojis=False)` → `"Hello"` |
|
|
262
|
+
| `normalize_repeating_chars` | Reduces repeated character sequences to a chosen number of characters. | `text` — Required; `keep=1` — Optional, number of repeated characters to keep. | `normalize_repeating_chars("Soooo", keep=1)` → `"So"` |
|
|
263
|
+
|
|
264
|
+
### 2. Text Removal and Emoji Handling
|
|
265
|
+
|
|
266
|
+
| Function | What It Does | Parameters (Required / Optional) | Example and Output |
|
|
267
|
+
|---|---|---|---|
|
|
268
|
+
| `remove_mentions` | Removes social media mentions such as `@user`. | `text` — Required | `remove_mentions("Hello @user")` → `"Hello"` |
|
|
269
|
+
| `remove_digits` | Removes numeric digits from the text. | `text` — Required | `remove_digits("Python 123")` → `"Python"` |
|
|
270
|
+
| `remove_hashtags` | Removes hashtags or keeps their words without the `#` symbol. | `text` — Required; `keep_word=False` — Optional, keeps the hashtag word when set to `True`. | `remove_hashtags("#Python", keep_word=True)` → `"Python"` |
|
|
271
|
+
| `remove_html` | Removes HTML tags and decodes HTML entities. | `text` — Required | `remove_html("<p>Hello & welcome</p>")` → `"Hello & welcome"` |
|
|
272
|
+
| `handle_emojis` | Removes emojis or converts them into text labels. | `text` — Required; `mode="remove"` — Optional, accepts `"remove"` or `"text"`. | `handle_emojis("Hello 😊", mode="remove")` → `"Hello"` |
|
|
273
|
+
|
|
274
|
+
### 3. Tokenization
|
|
275
|
+
|
|
276
|
+
| Function | What It Does | Parameters (Required / Optional) | Example and Output |
|
|
277
|
+
|---|---|---|---|
|
|
278
|
+
| `word_tokenize` | Splits text into individual words or tokens. | `text` — Required | `word_tokenize("Hello world!")` → `["Hello", "world"]` |
|
|
279
|
+
| `sent_tokenize` | Splits text into individual sentences. | `text` — Required | `sent_tokenize("Hello. How are you?")` → `["Hello.", "How are you?"]` |
|
|
280
|
+
|
|
281
|
+
### 4. Filtering and Contraction Expansion
|
|
282
|
+
|
|
283
|
+
| Function | What It Does | Parameters (Required / Optional) | Example and Output |
|
|
284
|
+
|---|---|---|---|
|
|
285
|
+
| `remove_stopwords` | Removes common English stopwords and optionally custom words. | `text` — Required; `custom_words=None` — Optional, additional words to remove; `extra_only=False` — Optional, removes only custom words when `True`. | `remove_stopwords("I like Python", custom_words=["like"])` → `"like Python"`* |
|
|
286
|
+
| `expand_contractions` | Expands English contractions into their full forms. | `text` — Required | `expand_contractions("I don't know")` → `"I do not know"` |
|
|
287
|
+
|
|
288
|
+
### 5. Slang Normalization
|
|
289
|
+
|
|
290
|
+
| Function | What It Does | Parameters (Required / Optional) | Example and Output |
|
|
291
|
+
|---|---|---|---|
|
|
292
|
+
| `normalize_slang` | Converts common internet slang and abbreviations into standard English words. | `text` — Required | `normalize_slang("u r gr8")` → `"you are great"` |
|
|
293
|
+
|
|
294
|
+
### 6. N-grams Generation
|
|
295
|
+
|
|
296
|
+
| Function | What It Does | Parameters (Required / Optional) | Example and Output |
|
|
297
|
+
|---|---|---|---|
|
|
298
|
+
| `ngrams` | Generates word N-grams from the input text. | `text` — Required; `n` — Required, number of words in each N-gram. | `ngrams("I love Python", 2)` → `[("I", "love"), ("love", "Python")]` |
|
|
299
|
+
| `char_ngrams` | Generates character N-grams from the input text. | `text` — Required; `n` — Required, number of characters in each N-gram. | `char_ngrams("hello", 2)` → `["he", "el", "ll", "lo"]` |
|
|
300
|
+
|
|
301
|
+
### 7. Accent and Arabic Normalization
|
|
302
|
+
|
|
303
|
+
| Function | What It Does | Parameters (Required / Optional) | Example and Output |
|
|
304
|
+
|---|---|---|---|
|
|
305
|
+
| `remove_accents` | Removes accents from Latin characters. | `text` — Required | `remove_accents("café")` → `"cafe"` |
|
|
306
|
+
| `normalize_arabic` | Removes Arabic diacritics and tatweel, and normalizes selected Arabic letter variants. | `text` — Required; `taa_marbuta=False` — Optional, converts `ة` to `ه` when set to `True`. | `normalize_arabic("أَهْلاً")` → `"اهلا"` |
|
|
307
|
+
|
|
308
|
+
### 8. Lemmatization
|
|
309
|
+
|
|
310
|
+
| Function | What It Does | Parameters (Required / Optional) | Example and Output |
|
|
311
|
+
|---|---|---|---|
|
|
312
|
+
| `lemmatize` | Converts supported English word forms into their base forms. | `text` — Required | `lemmatize("cats")` → `"cat"` |
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
## Pipeline API
|
|
316
|
+
|
|
317
|
+
| Method | Description |
|
|
318
|
+
|---|---|
|
|
319
|
+
| `Pipeline(steps)` | Creates a pipeline from registered steps and their parameters. |
|
|
320
|
+
| `transform(text)` | Applies all steps to one string. |
|
|
321
|
+
| `transform_batch(texts)` | Applies the pipeline to a list of strings. |
|
|
322
|
+
|
|
323
|
+
## TextCleaner API
|
|
324
|
+
| Usage | Description |
|
|
325
|
+
|---|---|
|
|
326
|
+
| `TextCleaner(language="en")` | Creates a cleaner instance. |
|
|
327
|
+
| `cleaner.step_name(text, **params)` | Calls a registered preprocessing step with its parameters. |
|
|
328
|
+
|
|
329
|
+
## Error Handling
|
|
330
|
+
PyTextPrep provides custom exceptions for common pipeline configuration errors.
|
|
331
|
+
|
|
332
|
+
| Exception | Description |
|
|
333
|
+
|---|---|
|
|
334
|
+
| `PyTextPrepError` | Base exception for library-specific errors. |
|
|
335
|
+
| `UnknownStepError` | Raised when a step name is not registered. |
|
|
336
|
+
| `InvalidStepParamsError` | Raised when invalid or unexpected parameters are provided. |
|
|
337
|
+
| `TypeError` | Raised when a function receives an input of an invalid type. |
|
|
338
|
+
|
|
339
|
+
Example:
|
|
340
|
+
|
|
341
|
+
```python
|
|
342
|
+
from pytextprep import Pipeline
|
|
343
|
+
|
|
344
|
+
Pipeline([("remove_url", {})])
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Expected error:
|
|
348
|
+
|
|
349
|
+
```text
|
|
350
|
+
UnknownStepError: 'remove_url' is not a step. Did you mean 'remove_urls'?
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
Another example:
|
|
354
|
+
|
|
355
|
+
```python
|
|
356
|
+
Pipeline([("remove_punctuation", {"keep_emoji": False})])
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
Expected error:
|
|
360
|
+
|
|
361
|
+
```text
|
|
362
|
+
InvalidStepParamsError: remove_punctuation() got an unexpected parameter 'keep_emoji'
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
Invalid input example:
|
|
366
|
+
|
|
367
|
+
```python
|
|
368
|
+
from pytextprep import lowercase
|
|
369
|
+
|
|
370
|
+
lowercase(42)
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
Expected error:
|
|
374
|
+
|
|
375
|
+
```text
|
|
376
|
+
TypeError: expected str, got int
|
|
377
|
+
```
|
|
378
|
+
## Known Limitations
|
|
379
|
+
|
|
380
|
+
-The built-in stopword and contraction resources focus on English.
|
|
381
|
+
|
|
382
|
+
-Arabic normalization handles selected character variants and diacritics; it is not a complete Arabic linguistic normalization system.
|
|
383
|
+
|
|
384
|
+
-Emoji detection and conversion cover common Unicode ranges but may not handle every complex multi-codepoint emoji sequence.
|
|
385
|
+
|
|
386
|
+
-The lemmatizer supports the implemented English rules and exceptions; it is not a full linguistic lemmatization engine.
|
|
387
|
+
|
|
388
|
+
-The Pipeline is designed for transformations that accept and return strings. Tokenization and N-gram functions that return -collections are intended to be used directly as standalone functions.
|
|
389
|
+
|
|
390
|
+
-Slang normalization depends on the entries available in the built-in slang dictionary.
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
## License
|
|
394
|
+
|
|
395
|
+
This project is open-source and is distributed under the MIT License.
|
|
396
|
+
|
|
397
|
+
See the [LICENSE](LICENSE) file for details.
|
|
398
|
+
|