# Path: t5/evaluation/qa_utils.py
# def _normalize_answer(text, punc_chars, punc_repl):
#   def remove_articles(s):
#   def replace_punctuation(s):
#   def white_space_fix(s):
# def normalize_trivia_qa(answer):
# def normalize_squad(answer):
# def _metric_max_over_ground_truths(metric_fn, ground_truths, prediction):
# def _exact_match_score(target, prediction):
# def _f1_score(target, prediction):
# def qa_metrics(targets, predictions):


from absl.testing import absltest
from t5.evaluation import qa_utils
"""Tests for t5.evaluation.qa_utils."""



class QaUtilsTest(absltest.TestCase):

  def test_normalize_trivia_qa(self):
    self.assertEqual(
        qa_utils.normalize_trivia_qa(
            "`Needs\tA_LOT of the 'normalization'.\"‘"),
        "needs lot of normalization",
    )
    self.assertEqual(
        qa_utils.normalize_trivia_qa("needs no normalization"),
        "needs no normalization",
    )

  def test_normalize_squad(self):
    self.assertEqual(
        qa_utils.normalize_squad("`Needs\tA_LOT of the 'normalization'.\"‘"),
        "needs alot of normalization‘",
    )
    self.assertEqual(
        qa_utils.normalize_squad("needs no normalization"),
        "needs no normalization",
    )

  def test_qa_metrics(self):
    with self.assertRaisesRegex(
        ValueError, "Number of targets and predictions must match."):

# Path: t5/evaluation/qa_utils.py
# def _normalize_answer(text, punc_chars, punc_repl):
#   def remove_articles(s):
#   def replace_punctuation(s):
#   def white_space_fix(s):
# def normalize_trivia_qa(answer):
# def normalize_squad(answer):
# def _metric_max_over_ground_truths(metric_fn, ground_truths, prediction):
# def _exact_match_score(target, prediction):
# def _f1_score(target, prediction):
# def qa_metrics(targets, predictions):


# Path: t5/evaluation/qa_utils_test.py
from absl.testing import absltest
from t5.evaluation import qa_utils

"""Tests for t5.evaluation.qa_utils."""



class QaUtilsTest(absltest.TestCase):

  def test_normalize_trivia_qa(self):
    self.assertEqual(
        qa_utils.normalize_trivia_qa(
            "`Needs\tA_LOT of the 'normalization'.\"‘"),
        "needs lot of normalization",
    )
    self.assertEqual(
        qa_utils.normalize_trivia_qa("needs no normalization"),
        "needs no normalization",
    )

  def test_normalize_squad(self):
    self.assertEqual(
        qa_utils.normalize_squad("`Needs\tA_LOT of the 'normalization'.\"‘"),
        "needs alot of normalization‘",
    )
    self.assertEqual(
        qa_utils.normalize_squad("needs no normalization"),
        "needs no normalization",
    )

  def test_qa_metrics(self):
    with self.assertRaisesRegex(
        ValueError, "Number of targets and predictions must match."):

      qa_utils.qa_metrics([["answer"]] * 6, ["answer"] * 5)