def read_examples(self, queries_file):
    """Read a json file into a list of Example."""
    self.max_qry_answers = 0
    with tf.gfile.Open(queries_file, "r") as reader:
      examples = []
      for ii, line in tqdm(enumerate(reader)):
        item = json.loads(line.strip())

        qas_id = str(ii)
        question_text = item["question"]
        answer_entities = [answer["kb_id"] for answer in item["answers"]]
        if item["entities"]:
          subject_entities = item["entities"][0]["kb_id"]
        else:
          subject_entities = 0

        if len(answer_entities) > self.max_qry_answers:
          self.max_qry_answers = len(answer_entities)

        inference_chain = "::".join(item["inference_chains"][0])

        bridge_entities = None
        if len(item["intermediate_entities"]) > 2:
          bridge_entities = [[
              bridge["kb_id"] for bridge in intermediate
          ] for intermediate in item["intermediate_entities"][1:-1]]
          self.has_bridge = True
          self.num_bridge = len(bridge_entities)

        if self.has_bridge:
          assert bridge_entities is not None, (qas_id)

        example = Example(
            qas_id=qas_id,
            question_text=question_text,
            subject_entity=[subject_entities],
            answer_entity=answer_entities,
            bridge_entity=bridge_entities,
            inference_chain=inference_chain)
        examples.append(example)
    tf.logging.info("Maximum answers per question = %d", self.max_qry_answers)

    return examples
Read a json file into a list of Example.
language/labs/drkit/input_fns.py