Skip to main content

An NLP Text Preprocessing Package

Project description

This package is all in one text preprocessing pipeline and takes text input in the form of pandas series and outputs as pandas series object.

All the text_processing sub-functions may be viewed here https://github.com/tariqjamil-bwp/pypi_projects/tree/main/tj_nlp

Installing: pip install tj_preproc

Usage: (by example)

  • from tj_text.tj_preproc import text_preprocessing_ds, text_preprocessing
  • df2 = df1.copy()
  • df2['input_data'] = text_preprocessing_ds(df2['Phrase'])

Note: It will not work with .apply(text_....) method, as .apply is item by item processing which may not be optimized at dataframe level.

Details:

text_preprocessing_ds(pdSeries) It has a variety of input flags, controlling the appropritae text preprocessing activity, and are by default set to True. The details of flags is as under:

** The function is optimized to take advantage of the multi threaded processors **

Arguments:

  1. pdSeries: A positional argument, of pandas series object type, and should contain text phrases to be preprocessed

** All following arguments are key-word type **

  1. NewLine removal: Parameter: 'newlines_tabs' This setting when enablesd causes the function to remove all the occurrences of newlines, tabs, and combinations like: \n, \.

    • Example:
      • Input : This is her \ first day at this place.\n Please,\t Be nice to her.\n
      • Output : This is her first day at this place. Please, Be nice to her.
  2. HTML Tags removal: Parameter: 'remove_html' This setting when enablesd causes the function to remove all the occurrences of html tags from the text.

    • Example:
      • Input : This is a nice place to live.
      • Output : This is a nice place to live.
  3. Hyper Links removal: This setting when enablesd causes the function to remove all the occurrences of links. Parameter: 'links'

  4. Removing extra white spaces: Parameter: 'extra_whitespace' This setting when enablesd causes the function to remove extra whitespaces from the text

    • Example:
      • Input : How are you doing ?
      • Output : How are you doing ?
  5. Accented Characters Removal: Parameter: 'accented_chars' This setting when enablesd causes the function to remove accented characters from the text contained within the Dataset.

    • Example:
      • Input : Málaga, àéêöhello
      • Output : Malaga, aeeohello
  6. Lower Casing: Parameter: 'lowercase' This setting when enablesd causes the function to convert text into lower case.

    • Example:
      • Input : The World is Full of Surprises!
      • Output : the world is full of surprises!
  7. Removing Character Repetitions: Parameter: 'repeatition' This setting when enablesd causes the function to reduce repeatition to two characters for alphabets and to one character for punctuations.

    • Example:
      • Input : Realllllllllyyyyy, Greeeeaaaatttt !!!!?....;;;;:)
      • Output : Reallyy, Greeaatt !?.;:)
  8. Expand Contractions: Parameter: 'contractions' This setting when enablesd causes the function to expand shortened words to the actual form. e.g. don't to do not

    • Example:
      • Input : ain't, aren't, can't, cause, can't've
      • Output : is not, are not, cannot, because, cannot have
  9. Removing Special Characters: Parameter: 'special_chars' This setting when enablesd causes the function to remove all the special characters except a preset list of characters as they have imp meaning in the text provided.

    • Example:
      • Input : Hello, T-a-r-i-q. Thi*s is $100.05 : the payment that you will recieve! (Is this okay?)
      • Output : Hello, Tariq. This is $100.05 : the payment that you will recieve! Is this okay?
  10. Removong Stop Words: Parameter: 'stop_words' This setting when enablesd causes the function to remove the stopwords which doesn't add much meaning to a sentence & they can be remove safely without comprimising meaning of the sentence.

    • Example:
      • Input : This is Tariq from karachi who came here to study.
      • Output : ["'This", 'Tariq', 'karachi', 'came', 'study', '.', "'"]
  11. Mis-spelled words Correction: Parameter: 'mis_spell' This setting when enablesd causes the function to correct spellings. Currently only English language is supported.

    • Example:
      • Input : This is OAkbar from Londn who came heree to studdy.
      • Output : This is Akbar from London who came here to study.
  12. Lamentization: Parameters: 'lemmatization_allow' This setting when enablesd causes the function to converts word to their root words without explicitely cut down as done in stemming.

    • Example:
      • Input : text reduced
      • Output : text reduce

**The unoptimized function also made part of the package for comparison purposes text_preprocessing(text) It accepts text string as parameter and therefore requires .apply method to operate or looping if needs selective preprocessing. It accepts same other (2-13) parameters as above.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tj_preproc-0.0.3.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tj_preproc-0.0.3-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file tj_preproc-0.0.3.tar.gz.

File metadata

  • Download URL: tj_preproc-0.0.3.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for tj_preproc-0.0.3.tar.gz
Algorithm Hash digest
SHA256 b7a9def29a0131d20625073e80291bc8e6ded7c86ef7cd71db89db495a992291
MD5 f5b296716faa74a0062892f089d75726
BLAKE2b-256 cffb418cebada010e8ccc0911205611a3e73f5a1ecb8a5304ace27724558cc4d

See more details on using hashes here.

File details

Details for the file tj_preproc-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: tj_preproc-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for tj_preproc-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fc00872c5a8f358f8bd31b6035c74dd4e75a1480deaf95cd8efb5d40d47d1ef3
MD5 f89be90441ee8b796c9ca5e9bfca4f15
BLAKE2b-256 1ef6fe9fd4825d62cdbef395c461ae50cc5ba6378008c11ef0c8d85cfd2cc79d

See more details on using hashes here.

Supported by

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