class_docstr: Natural Questions: A Benchmark for Question Answering Research.
class_docstr_tok: ["Natural","Questions",":","A","Benchmark","for","Question","Answering","Research","."]
docstr: Parse a single json line and emit an example dict.
docstr_tok: ["Parse","a","single","json","line","and","emit","an","example","dict","."]
code: def _parse_example_longt5(line):
      """Parse a single json line and emit an example dict."""
      ex_json = json.loads(line)
  
      def _pad_punctuation(text):
          """Adds spaces around punctuation."""
          # Add space around punctuation.
          text = re.sub(r"(\W)", r" \1 ", text)
          # Collapse consecutive whitespace into one space.
          text = re.sub(r"\s+", " ", text)
          return text
  
      def _get_context(json_dict):
          document_tokens = []
          for c in json_dict["long_answer_candidates"]:
              if not bool(c["top_level"]):
                  continue
              for pos in range(c["start_token"], c["end_token"]):
                  t = json_dict["document_tokens"][pos]
                  document_tokens.append(t["token"])
          context = " ".join(document_tokens)
          # Substitute newlines and tabs with spaces.
          context = re.sub(r"\n\t", " ", context)
          context = _pad_punctuation(context)
          return context
  
      def _has_short_answer(a):
          return bool(a["short_answers"])
  
      def _is_yes_no_answer(a):
          return a["yes_no_answer"] in ("YES", "NO")
  
      def _get_all_answers(json_dict):
          all_answers = []
          for a in json_dict["annotations"]:
              answer_tokens = []
              if _has_short_answer(a):
                  for sa in a["short_answers"]:
                      for pos in range(
                          sa["start_token"], sa["end_token"]
                      ):
                          answer_tokens.append(
                              _pad_punctuation(
                                  json_dict["document_tokens"][pos][
                                      "token"
                                  ]
                              )
                          )
                      answer = " ".join(answer_tokens)
                      all_answers.append(answer)
              elif _is_yes_no_answer(a):
                  all_answers.append(
                      _pad_punctuation(a["yes_no_answer"])
                  )
              else:
                  all_answers.append(_pad_punctuation("NULL"))
          return all_answers
  
      def _get_answer(all_answers):
          """Pick the first non NULL answer, if it exists."""
          for a in all_answers:
              if a != "NULL":
                  return a
          return "NULL"
  
      # Convert to str since some IDs cannot be represented by np.int64.
      id_ = str(ex_json["example_id"])
      all_answers = _get_all_answers(ex_json)
      return id_, {
          "id": id_,
          "question": _pad_punctuation(
              ex_json["question_text"].strip()
          ),
          "title": ex_json["document_title"].strip(),
          "context": _get_context(ex_json),
          "all_answers": all_answers,
          "answer": _get_answer(all_answers),
      }
  
file_path: datasets/tensorflow_datasets/datasets/natural_questions/natural_questions_dataset_builder.py
imports: import html
  import json
  import os
  import re
  from typing import Optional
  import numpy
  import tensorflow_datasets.public_api
label_desc: Use image node_id 4 for calling the Builder obj's underlying member method code with example usage: obj._parse_example_longt5(line) and returns: id_,  dict, text, context, bool, unknown, all_answers, str, a