code: def substitute_replacements_in_text(
      text: str,
      replacements: List[Tuple[int, int, str, float]],
      replace_hyphen_to_space: bool,
  ) -> str:
      """Substitute replacements to the input text, iterating from end to beginning, so that indexing does not change.
         Note that we expect intersecting replacements to be already filtered.
      Args:
          text: sentence;
          replacements: list of replacements, each is a tuple (begin, end, text, probability);
          replace_hyphen_to_space: if True, hyphens in replacements will be converted to spaces;
      Returns:
          corrected sentence
      """
      replacements.sort()
      last_begin = len(text) + 1
      corrected_text = text
      for begin, end, candidate, prob in reversed(replacements):
          if end > last_begin:
              print(
                  "WARNING: skip intersecting replacement [",
                  candidate,
                  "] in text: ",
                  text,
              )
              continue
          if replace_hyphen_to_space:
              candidate = candidate.replace("-", " ")
          corrected_text = (
              corrected_text[:begin] + candidate + corrected_text[end:]
          )
          last_begin = begin
      return corrected_text
  
imports: import json
  import math
  import random
  import re
  from collections import defaultdict, namedtuple
  from typing import Dict, List, Set, Tuple, Union
  import numpy
  from numba import jit
label_desc: Use image node_id 11 for calling a global function with example usage: substitute_replacements_in_text(text, replacements, replace_hyphen_to_space) and returns: corrected_text