code: def process(self, document):
      sentences = document.sentences
  
      cased_words = []
      sent_ids = []
      word_pos = []
      for sent_idx, sentence in enumerate(sentences):
          for word_idx, word in enumerate(sentence.words):
              cased_words.append(word.text)
              sent_ids.append(sent_idx)
              word_pos.append(word_idx)
  
      coref_input = {
          "document_id": "wb_doc_1",
          "cased_words": cased_words,
          "sent_id": sent_ids,
      }
      coref_input = self._model.build_doc(coref_input)
      results = self._model.run(coref_input)
      clusters = []
      for span_cluster in results.span_clusters:
          if len(span_cluster) == 0:
              continue
          span_cluster = sorted(span_cluster)
  
          # treat the longest span as the representative
          # break ties using the first one
          max_len = 0
          best_span = None
          for span_idx, span in enumerate(span_cluster):
              if span[1] - span[0] > max_len:
                  max_len = span[1] - span[0]
                  best_span = span_idx
  
          mentions = []
          for span in span_cluster:
              sent_id = sent_ids[span[0]]
              if sent_ids[span[1]] != sent_id:
                  raise ValueError(
                      "The coref model predicted a span that crossed two sentences!  Please send this example to us on our github"
                  )
              start_word = word_pos[span[0]]
              end_word = word_pos[span[1]]
              mentions.append(
                  CorefMention(sent_id, start_word, end_word)
              )
          representative = mentions[best_span]
          representative_text = extract_text(
              document,
              representative.sentence,
              representative.start_word,
              representative.end_word,
          )
  
          chain = CorefChain(
              len(clusters), mentions, representative_text, best_span
          )
          clusters.append(chain)
  
      document.coref = clusters
      return document
  
file_path: stanza/stanza/pipeline/coref_processor.py
imports: from stanza.models.common.utils import misc_to_space_after
  from stanza.models.coref.coref_chain import CorefMention, CorefChain
  from stanza.pipeline._constants import *
  from stanza.pipeline.processor import UDProcessor, register_processor
label_desc: Use image node_id 2 for calling the CorefProcessor obj's underlying member method code with example usage: obj.process(document) and returns: document