def entity_char_to_token(entity, sentence):
  """Takes Stanza entity and sentence objects and returns the start and end tokens for the entity.

  The misc value in a stanza sentence object contains a string with additional
  information, separated by a pipe character. This string contains the
  start_char and end_char for each token, along with other information. This is
  extracted and used to match the start_char and end char values in a span
  object to return the start and end tokens for the entity.

  Example entity:
    {'text': 'Barack Obama',
    'type': 'PERSON',
    'start_char': 0,
    'end_char': 13}
  Example sentence:
    [
      {'id': 1,
      'text': 'Barack',
      ...,
      'misc': 'start_char=0|end_char=7'},
      {'id': 2,
      'text': 'Obama',
      ...,
      'misc': 'start_char=8|end_char=13'}
    ]

  Args:
    entity: Stanza Span object
    sentence: Stanza Sentence object
  Returns:
    Returns the token index of start and end locations for the entity
  """
  start_token, end_token = None, None
  for i, v in enumerate(sentence.words):
    x = v.misc.split("|")
    if "start_char=" + str(entity.start_char) in x:
      start_token = i
    if "end_char=" + str(entity.end_char) in x:
      end_token = i + 1
  return start_token, end_token