def _rouge_calculation(hypotheses,
                       references1,
                       references2=[],
                       metrics=['rougeLsum']):
  """Internal function for rouge scoring.

  If two references are provided,
  the best score is chosen for each instance.

  Args:
    hypotheses: list of predicted long answers
    references1: list of references to score hypotheses against
    references2: optional list of references to score hypotheses against
    metrics: evaluation metric

  Returns:
    dictionary representation of rouge scores
  """

  if references2 == []:
    references2 = references1

  scorer = rouge_scorer.RougeScorer(metrics, use_stemmer=True)
  aggregator = scoring.BootstrapAggregator()

  for i in range(len(hypotheses)):
    scores1 = scorer.score(references1[i], hypotheses[i])
    scores2 = scorer.score(references2[i], hypotheses[i])
    if scores1['rougeLsum'].fmeasure > scores2['rougeLsum'].fmeasure:
      aggregator.add_scores(scores1)
    else:
      aggregator.add_scores(scores2)

  scores = {m: [] for m in metrics}

  for m in metrics:
    fmeasure = aggregator.aggregate()[m].mid.fmeasure
    scores[m].append(fmeasure)

  for m in scores:
    scores[m] = 100 * sum(scores[m]) / len(scores[m])

  return scores
Internal function for rouge scoring.

  If two references are provided,
  the best score is chosen for each instance.

  Args:
    hypotheses: list of predicted long answers
    references1: list of references to score hypotheses against
    references2: optional list of references to score hypotheses against
    metrics: evaluation metric

  Returns:
    dictionary representation of rouge scores
  
language/asqa/scoring.py