docs: def _form_output(span_doc: span, output_format: str, relations: Dict, patterns: List) -> str:
          """
          Form an output value according to user input of output_format
          Args:
              span_doc: span
              format: str
              relations: Dict
              patterns: List
  
          Returns: str
          """
  
          format_value = []
          output_inf = [a_pattern.in_output for a_pattern in patterns]
          for i in range(len(output_inf)):
              token_range = relations[i]
              if token_range and output_inf[i]:
                  format_value.append(span_doc[token_range[0]:token_range[1]].text)
  
          if not output_format:
              return " ".join(format_value)
  
          result_str = re.sub("{}", " ".join(format_value), output_format)
  
          positions = re.findall("{[0-9]+}", result_str)
  
          if not positions:
              return result_str
  
          position_indices = [int(x[1:-1]) for x in positions]
          if max(position_indices) < len(format_value):
              result_str = result_str.format(*format_value)
          else:
              try:
                  result_str = result_str.format("", *format_value)
              except:
                  positions = [x for x in positions if int(x[1:-1]) > len(format_value)-1 or int(x[1:-1]) < 0]
                  for pos in positions:
                      result_str = result_str.replace(pos, "")
                  result_str = result_str.format(*format_value)
  
          return result_str