pyevoc.preprocessing.corpus_statistics#
Corpus-level descriptive statistics.
This module computes descriptive statistics on raw textual data before linguistic preprocessing. The tokenisation is Unicode-aware and preserves words, contractions, numbers, hashtags, mentions, and emojis.
- class pyevoc.preprocessing.corpus_statistics.CorpusStatisticsConfig(text_col='text', doc_col='doc_id', user_col='user_id', source_col='source', time_col='time', lowercase=True, show_progress=True, as_percent=True)[source]#
Bases:
objectConfiguration for corpus-level descriptive statistics.
- Parameters:
- pyevoc.preprocessing.corpus_statistics.simple_tokenise(text)[source]#
Tokenise raw text using a Unicode-aware regular expression.
The function preserves: - words; - contractions; - numbers; - hashtags; - mentions; - emojis and other Unicode grapheme clusters.
- pyevoc.preprocessing.corpus_statistics.is_valid_stat_token(token)[source]#
Return True if a token should be retained for corpus statistics.
Empty strings, whitespace-only tokens, and punctuation-only tokens are removed. Emojis and symbolic Unicode grapheme clusters are retained.
- pyevoc.preprocessing.corpus_statistics.extract_tokens(texts, *, lowercase=True, show_progress=True)[source]#
Extract valid tokens from a sequence of raw texts.
- pyevoc.preprocessing.corpus_statistics.corpus_statistics(df, text_col='text', *, doc_col='doc_id', user_col='user_id', time_col='time', lowercase=True, show_progress=True, as_dataframe=True)[source]#
Compute corpus-level descriptive statistics.
- Parameters:
df (DataFrame) – Input dataframe.
text_col (str) – Name of the raw text column.
doc_col (str) – Name of the document identifier column.
user_col (str) – Name of the user identifier column.
source_col – Name of the source/community/platform column.
time_col (str) – Name of the timestamp column.
lowercase (bool) – If True, tokens are lowercased before computing lexical statistics.
show_progress (bool) – If True, display a progress bar during token extraction.
as_dataframe (bool) – If True, return a display-ready pandas DataFrame. If False, return a dictionary.
- Returns:
Corpus-level descriptive statistics.
- Return type: