docstr: Build a test file to supply to the coreference scoring perl script
          
docstr_tok: ["Build","a","test","file","to","supply","to","the","coreference","scoring","perl","script"]
code: def build_test_file(
      self,
      out_path=OUT_PATH,
      remove_singleton=True,
      print_all_mentions=False,
      debug=None,
  ):
      """Build a test file to supply to the coreference scoring perl script"""
      print("🌋 Building test file")
      self._prepare_clusters()
      self.dataloader.dataset.no_targets = True
      if not print_all_mentions:
          print("🌋 Build coreference clusters")
          for sample_batched, mentions_idx, n_pairs_l in zip(
              self.dataloader, self.mentions_idx, self.n_pairs
          ):
              scores, max_i = self.get_max_score(sample_batched)
              for m_idx, ind, n_pairs in zip(
                  mentions_idx, max_i, n_pairs_l
              ):
                  if (
                      ind < n_pairs
                  ):  # the single score is not the highest, we have a match !
                      prev_idx = m_idx - n_pairs + ind
                      if debug is not None and (
                          debug == -1
                          or debug == prev_idx
                          or debug == m_idx
                      ):
                          m1_doc, m1_idx = self.flat_m_idx[m_idx]
                          m1 = self.docs[m1_doc]["mentions"][m1_idx]
                          m2_doc, m2_idx = self.flat_m_idx[prev_idx]
                          m2 = self.docs[m2_doc]["mentions"][m2_idx]
                          print(
                              "We have a match between:",
                              m1,
                              "(" + str(m1_idx) + ")",
                              "and:",
                              m2,
                              "(" + str(m2_idx) + ")",
                          )
                      self._merge_coreference_clusters(prev_idx, m_idx)
          if remove_singleton:
              self.remove_singletons_clusters()
      self.dataloader.dataset.no_targets = False
  
      print("🌋 Construct test file")
      out_str = ""
      for doc, d_tokens, d_lookup, d_m_loc, d_m_to_c in zip(
          self.docs,
          self.tokens,
          self.lookup,
          self.m_loc,
          self.mention_to_cluster,
      ):
          out_str += (
              "#begin document ("
              + doc["name"]
              + "); part "
              + doc["part"]
              + "\n"
          )
          for utt_idx, (c_tokens, c_lookup) in enumerate(
              zip(d_tokens, d_lookup)
          ):
              for i, (token, lookup) in enumerate(
                  zip(c_tokens, c_lookup)
              ):
                  out_coref = ""
                  for m_str, mention, mention_cluster in zip(
                      doc["mentions"], d_m_loc, d_m_to_c
                  ):
                      m_start, m_end, m_utt, m_idx, m_doc = mention
                      if mention_cluster is None:
                          pass
                      elif m_utt == utt_idx:
                          if m_start in lookup:
                              out_coref += "|" if out_coref else ""
                              out_coref += "(" + unicode_(
                                  mention_cluster
                              )
                              if (m_end - 1) in lookup:
                                  out_coref += ")"
                              else:
                                  out_coref += ""
                          elif (m_end - 1) in lookup:
                              out_coref += "|" if out_coref else ""
                              out_coref += (
                                  unicode_(mention_cluster) + ")"
                              )
                  out_line = (
                      doc["name"]
                      + " "
                      + doc["part"]
                      + " "
                      + unicode_(i)
                      + " "
                      + token
                      + " "
                  )
                  out_line += "-" if len(out_coref) == 0 else out_coref
                  out_str += out_line + "\n"
              out_str += "\n"
          out_str += "#end document\n"
  
      # Write test file
      print("Writing in", out_path)
      with io.open(out_path, "w", encoding="utf-8") as out_file:
          out_file.write(out_str)
  
imports: import os
  import subprocess
  import io
  import pickle
  import torch
  from torch.utils.data import DataLoader
  from neuralcoref.train.conllparser import FEATURES_NAMES
  from neuralcoref.train.dataset import NCBatchSampler, padder_collate
  from neuralcoref.train.compat import unicode_
label_desc: Use image node_id 9 for calling the ConllEvaluator obj's underlying member method code with example usage: obj.build_test_file(out_path, remove_singleton, print_all_mentions, debug) without return types