pyevoc.preprocessing.cleaning#
Basic text cleaning for social-media corpora.
The module performs conservative, emoji-safe normalisation of raw textual data. It is designed for social-media corpora where URLs, contractions, emojis, hashtags, mentions, punctuation, and non-standard orthography may coexist.
The default behaviour follows the original PyEvoc analytical pipeline:
decode HTML entities;
normalise apostrophes;
expand English contractions;
replace URLs with a stable placeholder;
preserve emojis as independent grapheme-level units;
reduce exaggerated vowel repetitions;
remove control characters;
space punctuation without removing Unicode symbols;
normalise whitespace.
- class pyevoc.preprocessing.cleaning.CleaningConfig(lowercase=False, decode_html=True, replace_ampersand=True, normalise_apostrophes=True, expand_contractions=True, remove_urls=True, url_placeholder='URL', space_emojis=True, reduce_elongated_vowels=True, remove_control_chars=True, space_punctuation=True, normalise_whitespace=True, show_progress=True)[source]#
Bases:
objectConfiguration for basic text cleaning.
- Parameters:
lowercase (bool)
decode_html (bool)
replace_ampersand (bool)
normalise_apostrophes (bool)
expand_contractions (bool)
remove_urls (bool)
url_placeholder (str)
space_emojis (bool)
reduce_elongated_vowels (bool)
remove_control_chars (bool)
space_punctuation (bool)
normalise_whitespace (bool)
show_progress (bool)
- pyevoc.preprocessing.cleaning.is_emoji_grapheme(value)[source]#
Return True if a Unicode grapheme cluster is an emoji.
The function is robust to multi-codepoint emojis and modifiers.
- pyevoc.preprocessing.cleaning.separate_emojis(text)[source]#
Add spaces around emoji grapheme clusters without splitting them.
Examples
βgreatπβ -> βgreat πβ
βokππ½β -> βok ππ½β
- pyevoc.preprocessing.cleaning.clean_text(text, *, config=None, lowercase=None, remove_urls=None)[source]#
Clean a single text.
- Parameters:
text (object) β Raw textual input.
config (CleaningConfig | None) β Optional cleaning configuration.
lowercase (bool | None) β Optional override for
config.lowercase.remove_urls (bool | None) β Optional override for
config.remove_urls.
- Returns:
Cleaned text.
- Return type:
- pyevoc.preprocessing.cleaning.clean_corpus(df, text_col='text', output_col='clean_text', *, config=None, lowercase=None, remove_urls=None)[source]#
Apply basic cleaning to a dataframe.
- Parameters:
df (DataFrame) β Input dataframe.
text_col (str) β Name of the source text column.
output_col (str) β Name of the output cleaned-text column.
config (CleaningConfig | None) β Optional cleaning configuration.
lowercase (bool | None) β Optional override for
config.lowercase.remove_urls (bool | None) β Optional override for
config.remove_urls.
- Returns:
Copy of the input dataframe with an additional cleaned-text column.
- Return type: