Datasets:
File size: 1,860 Bytes
59da9af cfa80ae 59da9af 22c9e6d 59da9af cfa80ae 22c9e6d cfa80ae 59da9af |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
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))
output_file.parent.mkdir(exist_ok=True, parents=True)
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))
output_file.parent.mkdir(exist_ok=True, parents=True)
df.to_parquet(output_file, compression="gzip")
if __name__ == "__main__":
app()
|