pyevoc.preprocessing.annotation#
Stanza UD annotation utilities for PyEvoc.
This module converts a document-level dataframe into a token-level Universal
Dependencies table. The output intentionally follows the original notebook
schema used by the EVOC pipeline, because dependency-based collocation
extraction requires the original column names token, head_token_id and
dep_rel.
Canonical output columns#
The core token-level columns are:
doc_idparagraph_idsentence_idtoken_idpositiontokenlemmauposxposfeatshead_token_iddep_rel
If present in the input dataframe, user_id and time are copied to every
token row. No duplicate aliases such as text, head or deprel are
created here. If other modules still expect those aliases, they should be
updated to the canonical names above.
- class pyevoc.preprocessing.annotation.AnnotationConfig(text_col='text_clean', doc_id_col='post_id', user_col='user_id', time_col='time', language='en', processors='tokenize,pos,lemma,depparse', tokenize_no_ssplit=False, use_gpu=False, batch_size=128, show_progress=True, save_parquet=False, output_dir='annotated_outputs', output_name=None, save_emoji_sample=True)[source]#
Bases:
objectConfiguration for Stanza-based UD annotation.
- Parameters:
- pyevoc.preprocessing.annotation.annotate_with_stanza(df, config=AnnotationConfig())[source]#
Annotate a document-level dataframe with Stanza.
The returned dataframe is the correct input for dependency-based collocation extraction. In particular, it contains
token,head_token_idanddep_rel.- Parameters:
df (DataFrame)
config (AnnotationConfig)
- Return type:
DataFrame
- pyevoc.preprocessing.annotation.annotate_dataframe(df, df_name='df', *, doc_id_col='post_id', text_col='text_clean', user_col='user_id', time_col='time', batch_size=128, save_parquet=True, output_dir='annotated_outputs', show_progress=True, use_gpu=False)[source]#
Notebook-compatible wrapper around
annotate_with_stanza().This mirrors the original notebook call style:
anno_df = annotate_dataframe(df, "df")and saves
<df_name>_stanza_anno.parquetwhensave_parquet=True.
- pyevoc.preprocessing.annotation.annotation_diagnostics(anno_df, *, doc_col='doc_id', user_col='user_id', time_col='time')[source]#
Return a compact diagnostic table for an annotated token dataframe.
- pyevoc.preprocessing.annotation.dependency_diagnostics(anno_df, *, dep_rel_col='dep_rel', head_col='head_token_id')[source]#
Return diagnostics for dependency columns used by collocations.
- pyevoc.preprocessing.annotation.contains_emoji_grapheme(value)[source]#
Return True if a string contains at least one emoji grapheme.
- pyevoc.preprocessing.annotation.count_emoji_documents(df, *, text_col='text_clean')[source]#
Count documents containing at least one emoji grapheme.
- pyevoc.preprocessing.annotation.count_emoji_tokens(anno_df, *, token_col='token')[source]#
Count annotated tokens containing at least one emoji grapheme.
- pyevoc.preprocessing.annotation.emoji_token_sample(anno_df, *, n=30, token_col='token')[source]#
Return a sample of emoji-bearing annotated tokens.
- pyevoc.preprocessing.annotation.validate_annotation_input(df, config=AnnotationConfig())[source]#
Validate the input dataframe before annotation.
- Parameters:
df (DataFrame)
config (AnnotationConfig)
- Return type:
None