code: def extract_text(document, sent_id, start_word, end_word):
      sentence = document.sentences[sent_id]
      tokens = []
  
      # the coref model indexes the words from 0,
      # whereas the ids we are looking at on the tokens start from 1
      # here we will switch to ID space
      start_word = start_word + 1
      end_word = end_word + 1
  
      # For each position between start and end word:
      # If a word is part of an MWT, and the entire token
      # is inside the range, we use that Token's text for that span
      # This will let us easily handle words which are split into pieces
      # Otherwise, we only take the text of the word itself
      next_idx = start_word
      while next_idx < end_word:
          word = sentence.words[next_idx - 1]
          parent_token = word.parent
          if (
              isinstance(parent_token.id, int)
              or len(parent_token.id) == 1
          ):
              tokens.append(parent_token)
              next_idx += 1
          elif (
              parent_token.id[0] >= start_word
              and parent_token.id[1] < end_word
          ):
              tokens.append(parent_token)
              next_idx = parent_token.id[1] + 1
          else:
              tokens.append(word)
              next_idx += 1
  
      # We use the SpaceAfter or SpacesAfter attribute on each Word or Token
      # we chose in the above loop to separate the text pieces
      text = []
      for token in tokens:
          text.append(token.text)
          text.append(misc_to_space_after(token.misc))
      # the last token space_after will be discarded
      # so that we don't have stray WS at the end of the mention text
      text = text[:-1]
      return "".join(text)
  
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 1 for calling a global function with example usage: extract_text(document, sent_id, start_word, end_word) and returns: str