code: def test_rouge(cand, ref):
      """Calculate ROUGE scores of sequences passed as an iterator
      e.g. a list of str, an open file, StringIO or even sys.stdin
      """
      current_time = time.strftime(
          "%Y-%m-%d-%H-%M-%S", time.localtime()
      )
      tmp_dir = ".rouge-tmp-{}".format(current_time)
      try:
          if not os.path.isdir(tmp_dir):
              os.mkdir(tmp_dir)
              os.mkdir(tmp_dir + "/candidate")
              os.mkdir(tmp_dir + "/reference")
          candidates = [line.strip() for line in cand]
          references = [line.strip() for line in ref]
          assert len(candidates) == len(references)
          cnt = len(candidates)
          for i in range(cnt):
              if len(references[i]) < 1:
                  continue
              with open(
                  tmp_dir + "/candidate/cand.{}.txt".format(i),
                  "w",
                  encoding="utf-8",
              ) as f:
                  f.write(candidates[i])
              with open(
                  tmp_dir + "/reference/ref.{}.txt".format(i),
                  "w",
                  encoding="utf-8",
              ) as f:
                  f.write(references[i])
          r = pyrouge.Rouge155()
          r.model_dir = tmp_dir + "/reference/"
          r.system_dir = tmp_dir + "/candidate/"
          r.model_filename_pattern = "ref.#ID#.txt"
          r.system_filename_pattern = r"cand.(\d+).txt"
          rouge_results = r.convert_and_evaluate()
          results_dict = r.output_to_dict(rouge_results)
          return results_dict
      finally:
          pass
          if os.path.isdir(tmp_dir):
              shutil.rmtree(tmp_dir)
  
file_path: OpenNMT-py/tools/test_rouge.py
imports: import argparse
  import os
  import time
  import pyrouge
  import shutil
  import sys
  import codecs
  from onmt.utils.logging import init_logger, logger
label_desc: Use image node_id 1 for calling a global function with example usage: test_rouge(cand, ref) and returns: results_dict