# Path: sockeye_contrib/rouge.py
# def rouge(hypotheses, references):
#     """Calculates average rouge scores for a list of hypotheses and
#     references"""
# 
#     # Filter out hyps that are of 0 length
#     # hyps_and_refs = zip(hypotheses, references)
#     # hyps_and_refs = [_ for _ in hyps_and_refs if len(_[0]) > 0]
#     # hypotheses, references = zip(*hyps_and_refs)
# 
#     # Calculate ROUGE-1 F1, precision, recall scores
#     rouge_1 = [
#         rouge_n([hyp], [ref], 1) for hyp, ref in zip(hypotheses, references)
#     ]
#     rouge_1_f, rouge_1_p, rouge_1_r = map(np.mean, zip(*rouge_1))
# 
#     # Calculate ROUGE-2 F1, precision, recall scores
#     rouge_2 = [
#         rouge_n([hyp], [ref], 2) for hyp, ref in zip(hypotheses, references)
#     ]
#     rouge_2_f, rouge_2_p, rouge_2_r = map(np.mean, zip(*rouge_2))
# 
#     # Calculate ROUGE-L F1, precision, recall scores
#     rouge_l = [
#         rouge_l_sentence_level([hyp], [ref])
#         for hyp, ref in zip(hypotheses, references)
#     ]
#     rouge_l_f, rouge_l_p, rouge_l_r = map(np.mean, zip(*rouge_l))
# 
#     return {
#         "rouge_1/f_score": rouge_1_f,
#         "rouge_1/r_score": rouge_1_r,
#         "rouge_1/p_score": rouge_1_p,
#         "rouge_2/f_score": rouge_2_f,
#         "rouge_2/r_score": rouge_2_r,
#         "rouge_2/p_score": rouge_2_p,
#         "rouge_l/f_score": rouge_l_f,
#         "rouge_l/r_score": rouge_l_r,
#         "rouge_l/p_score": rouge_l_p,
#     }


import pytest
from sockeye_contrib import rouge
# permissions and limitations under the License.



test_cases = [(
              ["this is a test", "another test case"], ["this is a test case", "another test case"], 0.9444444394753087,
              0.928571423622449, 0.9338624338620563),
              (["this is a single test case"], ["this is a single test case"], 0.999999995, 0.999999995,
               0.9999999999995),
              (["single test case"], ["another single test case"], 0.8571428522448981, 0.7999999952000001,
               0.8241758241756372),
              (["no overlap between sentences"], ["this is another test case"], 0.0, 0.0, 0.0),
              (["exact match in the test case", "another exact match"],
               ["exact match in the test case", "another exact match"], 0.999999995, 0.999999995, 0.9999999999995)]


@pytest.mark.parametrize("hypotheses, references, rouge1_score, rouge2_score, rougel_score", test_cases)
def test_rouge_1(hypotheses, references, rouge1_score, rouge2_score, rougel_score):
    rouge_score = rouge.rouge_1(hypotheses, references)
    assert rouge_score == rouge1_score


@pytest.mark.parametrize("hypotheses, references, rouge1_score, rouge2_score, rougel_score", test_cases)
def test_rouge_2(hypotheses, references, rouge1_score, rouge2_score, rougel_score):
    rouge_score = rouge.rouge_2(hypotheses, references)
    assert rouge_score == rouge2_score


@pytest.mark.parametrize("hypotheses, references, rouge1_score, rouge2_score, rougel_score", test_cases)
def test_rouge_l(hypotheses, references, rouge1_score, rouge2_score, rougel_score):

# Path: sockeye_contrib/rouge.py
# def rouge(hypotheses, references):
#     """Calculates average rouge scores for a list of hypotheses and
#     references"""
# 
#     # Filter out hyps that are of 0 length
#     # hyps_and_refs = zip(hypotheses, references)
#     # hyps_and_refs = [_ for _ in hyps_and_refs if len(_[0]) > 0]
#     # hypotheses, references = zip(*hyps_and_refs)
# 
#     # Calculate ROUGE-1 F1, precision, recall scores
#     rouge_1 = [
#         rouge_n([hyp], [ref], 1) for hyp, ref in zip(hypotheses, references)
#     ]
#     rouge_1_f, rouge_1_p, rouge_1_r = map(np.mean, zip(*rouge_1))
# 
#     # Calculate ROUGE-2 F1, precision, recall scores
#     rouge_2 = [
#         rouge_n([hyp], [ref], 2) for hyp, ref in zip(hypotheses, references)
#     ]
#     rouge_2_f, rouge_2_p, rouge_2_r = map(np.mean, zip(*rouge_2))
# 
#     # Calculate ROUGE-L F1, precision, recall scores
#     rouge_l = [
#         rouge_l_sentence_level([hyp], [ref])
#         for hyp, ref in zip(hypotheses, references)
#     ]
#     rouge_l_f, rouge_l_p, rouge_l_r = map(np.mean, zip(*rouge_l))
# 
#     return {
#         "rouge_1/f_score": rouge_1_f,
#         "rouge_1/r_score": rouge_1_r,
#         "rouge_1/p_score": rouge_1_p,
#         "rouge_2/f_score": rouge_2_f,
#         "rouge_2/r_score": rouge_2_r,
#         "rouge_2/p_score": rouge_2_p,
#         "rouge_l/f_score": rouge_l_f,
#         "rouge_l/r_score": rouge_l_r,
#         "rouge_l/p_score": rouge_l_p,
#     }


# Path: test/unit/test_rouge.py
import pytest
from sockeye_contrib import rouge

# permissions and limitations under the License.



test_cases = [(
              ["this is a test", "another test case"], ["this is a test case", "another test case"], 0.9444444394753087,
              0.928571423622449, 0.9338624338620563),
              (["this is a single test case"], ["this is a single test case"], 0.999999995, 0.999999995,
               0.9999999999995),
              (["single test case"], ["another single test case"], 0.8571428522448981, 0.7999999952000001,
               0.8241758241756372),
              (["no overlap between sentences"], ["this is another test case"], 0.0, 0.0, 0.0),
              (["exact match in the test case", "another exact match"],
               ["exact match in the test case", "another exact match"], 0.999999995, 0.999999995, 0.9999999999995)]


@pytest.mark.parametrize("hypotheses, references, rouge1_score, rouge2_score, rougel_score", test_cases)
def test_rouge_1(hypotheses, references, rouge1_score, rouge2_score, rougel_score):
    rouge_score = rouge.rouge_1(hypotheses, references)
    assert rouge_score == rouge1_score


@pytest.mark.parametrize("hypotheses, references, rouge1_score, rouge2_score, rougel_score", test_cases)
def test_rouge_2(hypotheses, references, rouge1_score, rouge2_score, rougel_score):
    rouge_score = rouge.rouge_2(hypotheses, references)
    assert rouge_score == rouge2_score


@pytest.mark.parametrize("hypotheses, references, rouge1_score, rouge2_score, rougel_score", test_cases)
def test_rouge_l(hypotheses, references, rouge1_score, rouge2_score, rougel_score):

    rouge_score = rouge.rouge_l(hypotheses, references)