from .cider_scorer import CiderScorer
import pdb

class Cider:
    """Main Class to compute the CIDEr metric"""

    def __init__(self, test = None, refs = None, n = 4, sigma = 6.0):
        # set cider to sum over 1 to 4-grams
        self._n = n
        # set the standard deviation parameter for gaussian penalty
        self._sigma = sigma

    def compute_score(self, reference, hypothesis):
        """
        Compute CIDEr score

        Args:
            reference (list): Reference sentences ([[ref1a, ref1b, ref1c], ..., [refna, refnb]])
            hypothesis (list): Predicted sentences ([[hypo1], [hypo2], ..., [hypon]])

        Returns:
            cider (float): computed CIDEr score for the corpus
        """

        assert len(reference) == len(hypothesis)

        cider_scorer = CiderScorer(n = self._n, sigma = self._sigma)

        for id, hypo in enumerate(hypothesis):
            hypo = hypo
            ref = reference[id]

            # sanity check
            assert(type(hypo) is list)
            assert(len(hypo) >= 1)
            assert(type(ref) is list)
            assert(len(ref) > 0)

            cider_scorer += (hypo[0], ref)

        (score, scores) = cider_scorer.compute_score()

        return score, scores

    def method(self):
        return "CIDEr"
