A lib for text preprocessing
Project description
# Plane
[![Build Status](https://travis-ci.org/Momingcoder/Plane.svg?branch=master)](https://travis-ci.org/Momingcoder/Plane)
> **Plane** is a tool for shaping wood using muscle power to force the cutting blade over the wood surface.
> *from [Wikipedia](https://en.wikipedia.org/wiki/Plane_(tool))*
![plane(tool) from wikipedia](https://upload.wikimedia.org/wikipedia/commons/e/e3/Kanna2.gif)
This package is used for extracting or replacing specific parts from text, like URL, Email, HTML tags, telephone numbers and so on. Or just remove all unicode punctuations.
## Install
Python **3.x** only.
### pip
```python
pip install plane
```
### Install from source
```sh
python setup.py install
```
## Usage
### pattern
`Regex` is a namedtuple with 3 items:
* `name`
* `pattern`: Regular Expression
* `repl`: replacement tag, this will replace matched regex when using `replace` function
```python
# create new pattern
from plane import build_new_regex
custom_regex = build_new_regex('my_regex', r'(\d{4})', '<my-replacement-tag>')
```
Default Regex:
* `RESTRICT_URL`: only ASCII
* `EMAIL`: local-part@domain
* `TELEPHONE`: like xxx-xxxx-xxxx
* `SPACE`: ` `, `\t`, `\n`, `\r`, `\f`, `\v`
* `HTML`: HTML tags, Script part and CSS part
Use regex to `extract` or `replace`:
```python
from plane import EMAIL, extract, replace
text = 'fake@no.com & fakefake@nothing.com'
emails = extract(text, [EMAIL]) # this return a generator object
for e in emails:
print(e)
>>> Token(name='Email', value='fake@no.com', start=0, end=11)
>>> Token(name='Email', value='fakefake@nothing.com', start=14, end=34)
replace(text, [EMAIL])
>>> '<Email> & <Email>'
```
### punctuation
`remove_punctuation` will replace all unicode punctuations to `' '` or something you send to this function as paramter `repl`.
**Attention**: '+', '^', '$', '~' and some chars are not punctuation.
```python
from plane import remove_punctuation
text = 'Hello world!'
remove_punctuation(text)
>>> 'Hello world '
# replace punctuation with special string
remove_punctuation(text, '<P>')
>>> 'Hello world<P>'
```
[![Build Status](https://travis-ci.org/Momingcoder/Plane.svg?branch=master)](https://travis-ci.org/Momingcoder/Plane)
> **Plane** is a tool for shaping wood using muscle power to force the cutting blade over the wood surface.
> *from [Wikipedia](https://en.wikipedia.org/wiki/Plane_(tool))*
![plane(tool) from wikipedia](https://upload.wikimedia.org/wikipedia/commons/e/e3/Kanna2.gif)
This package is used for extracting or replacing specific parts from text, like URL, Email, HTML tags, telephone numbers and so on. Or just remove all unicode punctuations.
## Install
Python **3.x** only.
### pip
```python
pip install plane
```
### Install from source
```sh
python setup.py install
```
## Usage
### pattern
`Regex` is a namedtuple with 3 items:
* `name`
* `pattern`: Regular Expression
* `repl`: replacement tag, this will replace matched regex when using `replace` function
```python
# create new pattern
from plane import build_new_regex
custom_regex = build_new_regex('my_regex', r'(\d{4})', '<my-replacement-tag>')
```
Default Regex:
* `RESTRICT_URL`: only ASCII
* `EMAIL`: local-part@domain
* `TELEPHONE`: like xxx-xxxx-xxxx
* `SPACE`: ` `, `\t`, `\n`, `\r`, `\f`, `\v`
* `HTML`: HTML tags, Script part and CSS part
Use regex to `extract` or `replace`:
```python
from plane import EMAIL, extract, replace
text = 'fake@no.com & fakefake@nothing.com'
emails = extract(text, [EMAIL]) # this return a generator object
for e in emails:
print(e)
>>> Token(name='Email', value='fake@no.com', start=0, end=11)
>>> Token(name='Email', value='fakefake@nothing.com', start=14, end=34)
replace(text, [EMAIL])
>>> '<Email> & <Email>'
```
### punctuation
`remove_punctuation` will replace all unicode punctuations to `' '` or something you send to this function as paramter `repl`.
**Attention**: '+', '^', '$', '~' and some chars are not punctuation.
```python
from plane import remove_punctuation
text = 'Hello world!'
remove_punctuation(text)
>>> 'Hello world '
# replace punctuation with special string
remove_punctuation(text, '<P>')
>>> 'Hello world<P>'
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
plane-0.0.2-py3.5.egg
(12.2 kB
view details)
File details
Details for the file plane-0.0.2-py3.5.egg
.
File metadata
- Download URL: plane-0.0.2-py3.5.egg
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 432267e9e9a395d99d4c90b57fce93502b336cd231d4416d1fa9409db35e4cb4 |
|
MD5 | 90f24c48f1f7d579dd0d08949a489620 |
|
BLAKE2b-256 | f635471cfe5ab9faa7ec552a6163614163c5788b06bc4ef1383a26b6d0ee97d4 |