code: def output_conll(input_file, output_file, predictions, subtoken_map):
      prediction_map = {}
      for doc_key, clusters in predictions.items():
          start_map = collections.defaultdict(list)
          end_map = collections.defaultdict(list)
          word_map = collections.defaultdict(list)
          for cluster_id, mentions in enumerate(clusters):
              for start, end in mentions:
                  start, end = (
                      subtoken_map[doc_key][start],
                      subtoken_map[doc_key][end],
                  )
                  if start == end:
                      word_map[start].append(cluster_id)
                  else:
                      start_map[start].append((cluster_id, end))
                      end_map[end].append((cluster_id, start))
          for k, v in start_map.items():
              start_map[k] = [
                  cluster_id
                  for cluster_id, end in sorted(
                      v, key=operator.itemgetter(1), reverse=True
                  )
              ]
          for k, v in end_map.items():
              end_map[k] = [
                  cluster_id
                  for cluster_id, start in sorted(
                      v, key=operator.itemgetter(1), reverse=True
                  )
              ]
          prediction_map[doc_key] = (start_map, end_map, word_map)
  
      word_index = 0
      for line in input_file.readlines():
          row = line.split()
          if len(row) == 0:
              output_file.write("\n")
          elif row[0].startswith("#"):
              begin_match = re.match(BEGIN_DOCUMENT_REGEX, line)
              if begin_match:
                  doc_key = get_doc_key(
                      begin_match.group(1), begin_match.group(2)
                  )
                  start_map, end_map, word_map = prediction_map[doc_key]
                  word_index = 0
              output_file.write(line)
              output_file.write("\n")
          else:
              assert get_doc_key(row[0], row[1]) == doc_key
              coref_list = []
              if word_index in end_map:
                  for cluster_id in end_map[word_index]:
                      coref_list.append("{})".format(cluster_id))
              if word_index in word_map:
                  for cluster_id in word_map[word_index]:
                      coref_list.append("({})".format(cluster_id))
              if word_index in start_map:
                  for cluster_id in start_map[word_index]:
                      coref_list.append("({}".format(cluster_id))
  
              if len(coref_list) == 0:
                  row[-1] = "-"
              else:
                  row[-1] = "|".join(coref_list)
  
              output_file.write("   ".join(row))
              output_file.write("\n")
              word_index += 1
  
file_path: DeepKE/src/deepke/triple_extraction/ASP/metrics/conll.py
imports: import re
  import tempfile
  import subprocess
  import operator
  import collections
  import logging
label_desc: Use image node_id 2 for calling a global function with example usage: output_conll(input_file, output_file, predictions, subtoken_map) without return types