code: def _to_span(x, idx=0):
      
      if isinstance(x, Candidate):
          return x[idx].context
      elif isinstance(x, Mention):
          return x.context
      elif isinstance(x, TemporarySpanMention):
          return x
      else:
          raise ValueError(f"{type(x)} is an invalid argument type")
docs: Convert a Candidate, Mention, or Span to a span.