def make_tydi_answer(contexts: Text, answer: Mapping[Text, Any]) -> Answer:
  """Makes an Answer object following TyDi conventions.

  Args:
    contexts: String containing the context.
    answer: Dictionary with `span_start` and `input_text` fields.

  Returns:
    An Answer object. If the Answer type is YES or NO or PASSAGE, the text
    of the answer is the passage answer. If the answer type is UNKNOWN,
    the text of the answer is empty.
  """
  start = answer["span_start"]
  end = answer["span_end"]
  input_text = answer["input_text"]

  if (answer["candidate_id"] == -1 or start >= byte_len(contexts) or
      end > byte_len(contexts)):
    answer_type = AnswerType.UNKNOWN
    start = 0
    end = 1
  elif input_text.lower() == "yes":
    answer_type = AnswerType.YES
  elif input_text.lower() == "no":
    answer_type = AnswerType.NO
  elif input_text.lower() == "passage":
    answer_type = AnswerType.PASSAGE
  else:
    answer_type = AnswerType.MINIMAL

  return Answer(
      answer_type, text=byte_slice(contexts, start, end), offset=start)
Makes an Answer object following TyDi conventions.

  Args:
    contexts: String containing the context.
    answer: Dictionary with `span_start` and `input_text` fields.

  Returns:
    An Answer object. If the Answer type is YES or NO or PASSAGE, the text
    of the answer is the passage answer. If the answer type is UNKNOWN,
    the text of the answer is empty.
  
language/canine/tydiqa/data.py