cleantext
cleantext is a an open-source python package to clean raw text data. Source code for the library can be found here.
Features
cleantext has two main methods,
- clean: to clean raw text and return the cleaned text
- clean_words: to clean raw text and return a list of clean words
cleantext can apply all, or a selected combination of the following cleaning operations:
- Remove extra white spaces
- Convert the entire text into a uniform lowercase
- Remove digits from the text
- Remove punctuations from the text
- Remove or replace the part of text with custom regex
- Remove stop words, and choose a language for stop words ( Stop words are generally the most common words in a language with no significant meaning such as is, am, the, this, are etc.)
- Stem the words (Stemming is a process of converting words with similar meaning into a single word. For example, stemming of words run, runs, running will result run, run, run)
Installation
cleantext requires Python 3 and NLTK to execute.
To install using pip, use
pip install cleantext
Usage
- Import the library:
import cleantext
- Choose a method:
To return the text in a string format,
cleantext.clean("your_raw_text_here")
To return a list of words from the text,
cleantext.clean_words("your_raw_text_here")
To choose a specific set of cleaning operations,
cleantext.clean_words("your_raw_text_here",
clean_all= False # Execute all cleaning operations
extra_spaces=True , # Remove extra white spaces
stemming=True , # Stem the words
stopwords=True ,# Remove stop words
lowercase=True ,# Convert to lowercase
numbers=True ,# Remove all digits
punct=True ,# Remove all punctuations
reg: str = '<regex>', # Remove parts of text based on regex
reg_replace: str = '<replace_value>', # String to replace the regex used in reg
stp_lang='english' # Language for stop words
)
Examples
import cleantext
cleantext.clean('This is A s$ample !!!! tExt3% to cleaN566556+2+59*/133', extra_spaces=True, lowercase=True, numbers=True, punct=True)
returns,
'this is a sample text to clean'
import cleantext
cleantext.clean_words('This is A s$ample !!!! tExt3% to cleaN566556+2+59*/133')
returns,
['sampl', 'text', 'clean']
from cleantext import clean
text = "my id, name1@dom1.com and your, name2@dom2.in"
clean(text, reg=r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", reg_replace='email', clean_all=False)
returns,
"my id, email and your, email"
License
MIT
For any questions, issues, bugs, and suggestions please visit here
Metadata
Release files for cleantext 1.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cleantext-1.1.4.tar.gz | 4.2 kB | Without provenance | Details for cleantext-1.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cleantext-1.1.4-py3-none-any.whl | Python 3 | none | any | Details for cleantext-1.1.4-py3-none-any.whl |
Total release size: 9.1 kB
Release files / cleantext-1.1.4.tar.gz
| Download URL | cleantext-1.1.4.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
854003de912406d8d821623774b307dc6f0626fd9fac0bdc5d24864ee3f37578
|
|
BLAKE2b-256 checksum How to use checksums |
9e39883774dadb46a8ea348ddbdc9dfdb9aaa1a104825e65ee9ebe9a375f46e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|
Release files / cleantext-1.1.4-py3-none-any.whl
| Download URL | cleantext-1.1.4-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
138a658a8084796793910c876140002435ffc7ce51a9abf28d2a6b059a7a4d13
|
|
BLAKE2b-256 checksum How to use checksums |
dfd0bd954cf316c1d3a605a9bc29d2cf2bbd388b82d2626b60ab92e8d18457a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|
Security for cleantext 1.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.