pyevoc.analysis.quadrants#
EVOC thresholding, quadrant assignment, and compact HTML reporting.
This module assigns terms to the four classical EVOC/HEM quadrants after term-level statistics, concreteness labelling, and emoji description labelling have been computed.
The module implements the EVOC-ready logic used in PyEvoc:
optional minimal-frequency filtering;
POS-specific AFE and AOE thresholds;
user-level or document-level relative diffusion;
rounded comparison values for stable table construction;
diffusion/salience classes;
ordered quadrant labels;
publication-ready EVOC table;
threshold and quadrant diagnostics;
optional compact HTML reports by UPOS category.
The expected input is a term-level dataframe containing at least:
term
upos
term_type
n_docs or n_posts
n_users
R_pos
R_struct
S
Rank
freq_for_quadrant
user_penetration
posts_per_user
Optional enrichment columns such as concreteness_label and
emoji_description are preserved when available.
- class pyevoc.analysis.quadrants.QuadrantConfig(minimal_freq=2, round_digits=2, focal_upos=<factory>, quadrant_order=<factory>, diffusion_basis='user_penetration', term_col='term', upos_col='upos', term_type_col='term_type', n_docs_col='n_docs', n_posts_col='n_posts', n_users_col='n_users', r_pos_col='R_pos', r_struct_col='R_struct', salience_col='S', rank_col='Rank', freq_col='freq_for_quadrant', user_penetration_col='user_penetration', document_penetration_col='document_penetration', post_penetration_col='post_penetration', posts_per_user_col='posts_per_user', concreteness_score_col='concreteness_score', concreteness_label_col='concreteness_label', concreteness_in_lexicon_col='concreteness_in_lexicon', emoji_description_col='emoji_description', human_readable=True, generate_html=False, html_output_dir='evoc_outputs', html_top_n=20, html_max_width_px=950, verbose=True)[source]#
Bases:
objectConfiguration for EVOC quadrant assignment and optional HTML reporting.
- Parameters:
minimal_freq (int)
round_digits (int)
diffusion_basis (str)
term_col (str)
upos_col (str)
term_type_col (str)
n_docs_col (str)
n_posts_col (str)
n_users_col (str)
r_pos_col (str)
r_struct_col (str)
salience_col (str)
rank_col (str)
freq_col (str)
user_penetration_col (str)
document_penetration_col (str)
post_penetration_col (str)
posts_per_user_col (str)
concreteness_score_col (str)
concreteness_label_col (str)
concreteness_in_lexicon_col (str)
emoji_description_col (str)
human_readable (bool)
generate_html (bool)
html_top_n (int)
html_max_width_px (int)
verbose (bool)
- pyevoc.analysis.quadrants.format_value(value, digits=2)[source]#
Format a numeric value for EVOC compact HTML tables.
- pyevoc.analysis.quadrants.format_int(value)[source]#
Format an integer-like value for EVOC compact HTML tables.
- pyevoc.analysis.quadrants.concreteness_class(label)[source]#
Return a CSS class for a concreteness label.
- pyevoc.analysis.quadrants.get_threshold_values(pos_thresholds_round_df, upos)[source]#
Return formatted AFE/AOE threshold values for one UPOS category.
- pyevoc.analysis.quadrants.quadrant_rule_label(quadrant, afe, aoe)[source]#
Return the rule label printed under each quadrant title.
- pyevoc.analysis.quadrants.select_top_terms(df, quadrant, top_n=20)[source]#
Select the top terms for one quadrant using the legacy EVOC ordering.
- pyevoc.analysis.quadrants.build_quadrant_block(df, quadrant, upos, afe, aoe, top_n=20)[source]#
Build one HTML card for a given quadrant and UPOS category.
- pyevoc.analysis.quadrants.build_evoc_html_for_upos(evoc_quadrants_df, upos, pos_thresholds_round_df, *, output_dir='evoc_outputs', top_n=20, max_width_px=950)[source]#
Write the compact EVOC HTML report for one UPOS category.
- pyevoc.analysis.quadrants.generate_evoc_html_reports(evoc_quadrants_df, pos_thresholds_round_df, *, output_dir='evoc_outputs', top_n=20, max_width_px=950, upos_values=None)[source]#
Generate compact EVOC HTML reports for the requested UPOS categories.
- pyevoc.analysis.quadrants.assign_evoc_quadrants(term_stats_df, *, minimal_freq=2, focal_upos=None, quadrant_order=None, round_digits=2, diffusion_basis='user_penetration', generate_html=False, html_output_dir='evoc_outputs', html_top_n=20, html_max_width_px=950, config=None)[source]#
Assign EVOC quadrants using relative AFE and mean AOE thresholds.
- Parameters:
term_stats_df (DataFrame) – Term-level dataframe.
minimal_freq (int) – Minimal absolute frequency used to retain terms for quadrant assignment.
focal_upos (set[str] | None) – POS categories retained for EVOC assignment.
quadrant_order (list[str] | None) – Ordered quadrant labels.
round_digits (int) – Number of digits used for rounded threshold comparisons.
diffusion_basis (str) – Relative diffusion variable used to compute AFE thresholds. Supported values are
user_penetration,document_penetration,post_penetrationanddiffusion_penetration.generate_html (bool) – If True, write compact EVOC HTML reports by UPOS category.
html_output_dir (str | Path) – Directory where HTML files are written.
html_top_n (int) – Number of terms displayed in each quadrant card.
html_max_width_px (int) – Maximum width of the generated HTML page.
config (QuadrantConfig | None) – Optional complete configuration. If supplied, explicit keyword arguments above are ignored unless they are already encoded in config.
- Returns:
evoc_quadrants_df,quadrant_counts_dfandpos_thresholds_round_df.- Return type:
Notes
For backward compatibility, the function always returns three objects. When HTML reports are generated, their paths are stored in
evoc_quadrants_df.attrs["html_outputs"].
- pyevoc.analysis.quadrants.assign_quadrants(term_stats_df, *, config=None)[source]#
Alias for
assign_evoc_quadrants.- Parameters:
term_stats_df (DataFrame)
config (QuadrantConfig | None)
- Return type:
tuple[DataFrame, DataFrame, DataFrame]