def _get_all_facts(in_file):
  """Read all facts in inference chains."""
  facts = set()
  with tf.gfile.Open(in_file) as f:
    for line in f:
      item = json.loads(line.strip())
      for ir, relation in enumerate(item["inference_chains"][0]):
        for subj in item["intermediate_entities"][ir]:
          for obj in item["intermediate_entities"][ir + 1]:
            if relation.endswith("-inv"):
              facts.add(obj["text"].lower() + "::" + relation[:-4] + "::" +
                        subj["text"].lower())
            else:
              facts.add(subj["text"].lower() + "::" + relation + "::" +
                        obj["text"].lower())
  return facts
Read all facts in inference chains.
language/labs/drkit/metaqa/preprocessing/distantly_supervise.py