Light Text Pre-processing
Light Text Pre-processing is an easy-to-use python module that permits to apply a chain of built-in regex rules to a input string. Regex rules are stored in a separate YML file and compiled at run-time. The compiling mechanism and how to add a custom regex are described below.
How it works
Package reads a list of regex from light_text_prepro/rules/regex.yml. Each row in regex.yml identifies a regex rule such as user_tag: '"@[0-9a-z](\.?[0-9a-z])*"'. In this row, user_tag is the key of the regex, whereas the '"@[0-9a-z](\.?[0-9a-z])*"'is its value.
At run-time, the package reads the regex.yml and compiles a method for each regex, the method is named as the the key of the row. For example, at the end of the process, you will be able to call the user_tag()method, that permit to match the user tagged. Each method has the optional parameter replace_with that allow you to replace the string matched by regex rule with an arbitrary text.
Package installation
List of Regex
user_tag: '"(?<![\w@])@([\w@]+(?:[.!][\w@]+)*)"'
email: '"([^@|\s]+@[^@]+\.[^@|\s]+)"'
url: '"(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})"'
punctuation: '"[-!`?,.\":;]"'
parentheses: '"[\[\]{}()]"'
special_chars: '"[$%^&*_+|~=<>:;\\]"'
ip_address: '"(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"'
html_tag: '"^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$"'
tab_new_line: '"(\n|\t|\r)"'
multiple_space: '"[ ]+"'
emoji: '"[^\u1F600-\u1F6FF\s]"'
If you are happy wiht the list above, you can install the package via pip.
pip install light-text-prepro
How to use
from light_text_prepro.lprepro import LPrePro
...
obj = LPrePro()
...
result = obj.set_text('Hey @username, this is my email my@email.com') \
.user_tag(replace_with='[user]') \
.email(replace_with='[email]') \
.get_text()
# result -> Hey [user], this is my email [email]
Otherwise, if you want to contribute to enrich the package adding your regex rule, please follow section below.
How to add a regex rules
Setup project
$> git clone https://github.com/Arfius/light-text-prepro.git
$> cd light-text-prepro
$> pip install poetry flake8
$> poetry install
Add new regex
- Open
light_text_prepro/rules/regex.ymland add a new row. Make sure to use a unique key for the rule. If you get issue adding the regex rule, use any online regex validation tool and export the regex rule for python. (i.e. https://regex101.com/ => FLAVOR python => Copy to clipboard ) - Add a
unit testsunder thetestsfolder and make all test passed. Use$> poetry run pytestto run unit tests. - Update the section
List of Regexat the end of this file. - Create a Pull Request
Metadata
Release files for light-text-prepro 0.3.5
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 |
|---|---|---|---|---|
| light-text-prepro-0.3.5.tar.gz | 4.3 kB | Without provenance | Details for light-text-prepro-0.3.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| light_text_prepro-0.3.5-py3-none-any.whl | Python 3 | none | any | Details for light_text_prepro-0.3.5-py3-none-any.whl |
Total release size: 9.7 kB
Release files / light-text-prepro-0.3.5.tar.gz
| Download URL | light-text-prepro-0.3.5.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
01cdea4c1225dd963ad99efe12bab66c095fc747621b7b5754c5389dc56de378
|
|
BLAKE2b-256 checksum How to use checksums |
9fe12bd6e741f8237a0844ceec2bce5d73b7aa425f36f4b2ab35ca024abd0ba7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.0
|
Release files / light_text_prepro-0.3.5-py3-none-any.whl
| Download URL | light_text_prepro-0.3.5-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2db93a1c5fb7cdec7013501aadcac077d7025d60a0476988da5b86370e44fdc1
|
|
BLAKE2b-256 checksum How to use checksums |
ab7ed9881e891b0b5771008f1be4fdfc7ef8fe86214f2dcb66b912a4443dc527
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.0
|
Security for light-text-prepro 0.3.5
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.