A utility for cleaning social media text.
Project description
SocialPreText
SocialPreText is a professional-grade Python utility for cleaning and preprocessing social media text. It is designed to prepare noisy data for Natural Language Processing (NLP) tasks by normalizing slang, contractions, and social media-specific tokens.
Installation
Install the package directly from PyPI using pip:
pip install socialpretext
Quick Start: The One-Step Solution
The clean_all function is the primary entry point. It runs a pre-defined sequence of cleaning steps to transform messy text into clean, usable English.
Python
from socialpretext import clean_all
raw_text = "OMG idk, @user! This update is lit 🔥 Check it out: [https://example.com](https://example.com) #tech"
# Run the default cleaning pipeline
cleaned = clean_all(raw_text)
print(cleaned)
# Output: "oh my god i do not know this update is amazing check it out"
API Reference & Function Syntaxes
Below are the functions available in the package. Each can be imported and used individually for granular control over your text processing.
The Main Pipeline
socialpretext.clean_all(text, pipeline_steps=None): The master function. Accepts a string and an optional list of steps to run. If no steps are provided, it runs the full default suite.
Content Expansion
socialpretext.expand_slang(text): Converts internet shorthand into formal English. Example: "idk" becomes "I do not know".
socialpretext.expand_contractions(text): Expands standard English contractions. Example: "it's" becomes "it is".
Token Removal
socialpretext.remove_urls(text): Strips out http, https, and www web links.
socialpretext.remove_mentions(text): Removes @username mentions from the text.
socialpretext.remove_hashtags(text): Removes #hashtags while keeping the rest of the sentence intact.
socialpretext.remove_punctuation(text): Strips all standard punctuation marks (e.g., !, ?, .).
Emoji Handling
socialpretext.remove_emojis(text): Completely deletes emoji characters from the string.
socialpretext.demojize(text): Replaces emojis with their text descriptions. Example: "🔥" becomes ":fire:".
Formatting
socialpretext.normalize_whitespace(text): Fixes formatting by replacing multiple spaces or newlines with a single space.
Author
Akash Goyal (akashpgoyal@gmail.com)
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 Distribution
socialpretext-0.1.2.tar.gz
(6.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file
socialpretext-0.1.2.tar.gz.File metadata
File hashes
5c89dedb85c496f76b70692aff3dbb922485ed52fe056ab5d390dc206e29c9b969e622198950ce94ce528d4bac740254a3ab3892f72ea37e0a9db6a2d3fb2122bed2df0a32d45e75551617eb1da40c4bSee more details on using hashes here.