Skip to main content

A lib for text preprocessing

Project description

Build Status

Plane is a tool for shaping wood using muscle power to force the cutting blade over the wood surface.
– from Wikipedia.
plane(tool) from wikipedia

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

pip install plane

Install from source

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

# 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: r'\s'

  • HTML: HTML tags, Script part and CSS part

Use regex to extract or replace:

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.

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


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 Distributions

plane-0.0.3-py3.5.egg (12.3 kB view details)

Uploaded Source

plane-0.0.3-py2.py3-none-any.whl (8.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file plane-0.0.3-py3.5.egg.

File metadata

  • Download URL: plane-0.0.3-py3.5.egg
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for plane-0.0.3-py3.5.egg
Algorithm Hash digest
SHA256 a03f055cc81addab33103886c66dce3a5d8e7f2eda955952e0c8b7e23ca17b1f
MD5 519f004a4bad534218b76d6d9d586f6c
BLAKE2b-256 5111e697e024192757edc8b45e95137c36830f8b5f38ea417bc5c04f2ee9d415

See more details on using hashes here.

File details

Details for the file plane-0.0.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for plane-0.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d1ce979ba90128e6f47a38b1f1663e11626fa74dd5d378419415909b916ba788
MD5 76b3066275b92a45b765d6f059340e63
BLAKE2b-256 20b52cd883533f628f8b5af7f7d265afbedf9ce3b2ce5ba51bb1b663342ef38f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page