from pathlib import Path from typing import Annotated import typer from .alignment import ( find_closest_text, to_aligned_character_indices_series, to_character_indices_series, ) from .data import read_aste_file, read_sem_eval_file from .sentiment import to_nice_sentiment app = typer.Typer() @app.command() def aste( aste_file: Annotated[Path, typer.Option()], output_file: Annotated[Path, typer.Option()], ) -> None: df = read_aste_file(aste_file) df = df.explode("triples") df = df.reset_index(drop=False) df = df.merge( df.apply(to_character_indices_series, axis="columns"), left_index=True, right_index=True, ) df["sentiment"] = df.triples.apply(lambda triple: to_nice_sentiment(triple[2])) df = df.drop(columns=["triples"]) print(df.sample(3)) df.to_parquet(output_file, compression="gzip") @app.command() def sem_eval( aste_file: Annotated[Path, typer.Option()], sem_eval_file: Annotated[Path, typer.Option()], output_file: Annotated[Path, typer.Option()], ) -> None: df = read_aste_file(aste_file) sem_eval_df = read_sem_eval_file(sem_eval_file) df["original"] = df.text df["text"] = find_closest_text(original=df.original, replacement=sem_eval_df.text) df = df.explode("triples") df = df.reset_index(drop=False) df = df.merge( df.apply(to_aligned_character_indices_series, axis="columns"), left_index=True, right_index=True, ) df["sentiment"] = df.triples.apply(lambda triple: to_nice_sentiment(triple[2])) df = df.drop(columns=["original", "triples"]) print(df.sample(3)) df.to_parquet(output_file, compression="gzip") if __name__ == "__main__": app()