from pathlib import Path
from typing import Tuple

import click
from rxn.utilities.files import load_list_from_file

from paragraph2actions.analysis import (
    action_string_validity,
    full_sentence_accuracy,
    levenshtein_similarity,
    modified_bleu,
    partial_accuracy,
)


@click.command()
@click.option(
    "--ground_truth_file",
    "-g",
    required=True,
    type=click.Path(exists=True, dir_okay=False, path_type=Path),
    help="File containing the ground truth",
)
@click.option(
    "--prediction_files",
    "-p",
    multiple=True,
    type=click.Path(exists=True, dir_okay=False, path_type=Path),
    help="File containing the translations to compare with the ground truth",
)
def main(ground_truth_file: Path, prediction_files: Tuple[Path, ...]) -> None:
    """Calculate metrics for predictions generated by one or several translation models"""

    ground_truth = load_list_from_file(ground_truth_file)

    predictions = []
    for prediction_file in prediction_files:
        predictions.append(load_list_from_file(prediction_file))

    for filename, p in zip(prediction_files, predictions):
        print(filename)
        print("Full sentence accuracy, pr:", full_sentence_accuracy(ground_truth, p))
        print("String validity, pr:", action_string_validity(p))
        print("BLEU, pr:", modified_bleu(ground_truth, p))
        print("Levenshtein, pr:", levenshtein_similarity(ground_truth, p))
        print("100% accuracy, pr:", partial_accuracy(ground_truth, p, 1.0))
        print("90% accuracy, pr:", partial_accuracy(ground_truth, p, 0.9))
        print("75% accuracy, pr:", partial_accuracy(ground_truth, p, 0.75))
        print()


if __name__ == "__main__":
    main()
