class_docstr: Read a knowledge graph to memory
class_docstr_tok: ["Read","a","knowledge","graph","to","memory"]
docstr: Create a numpy store for training or validation tuples.
docstr_tok: ["Create","a","numpy","store","for","training","or","validation","tuples","."]
code: def create_tuple_store(self, train_graph=None, only_one_hop=False):
      """Create a numpy store for training or validation tuples."""
      self.tuple_store = []
      skipped = 0
      for e1 in self.kg_data:
          for e2 in self.kg_data[e1]:
              if only_one_hop and train_graph:
                  reachable = (
                      e1 in train_graph.kg_data
                      and e2 in train_graph.kg_data[e1]
                  )
                  reachable = reachable or (
                      e1 in train_graph.kg_text_data
                      and e2 in train_graph.kg_text_data[e1]
                  )
              else:
                  reachable = True
              if reachable:
                  for r in self.kg_data[e1][e2]:
                      self.tuple_store.append((e1, r, e2))
                      # if self.mode == "train":
                      self.all_reachable_e2[(e1, r)].add(e2)
                      # if self.add_reverse_graph:
                      self.all_reachable_e2_reverse[(e2, r)].add(e1)
              else:
                  skipped += len(self.kg_data[e1][e2])
      self.tuple_store = np.array(self.tuple_store)
      logging.info(
          "Unreachable %s tuples skipped: %d", self.mode, skipped
      )
      logging.info(
          "Remaining %s tuples: %d",
          self.mode,
          self.tuple_store.shape[0],
      )
  
file_path: neural-structured-learning/research/a2n/graph.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from collections import defaultdict
  import csv
  from absl import logging
  import numpy
label_desc: Use image node_id 6 for calling the Graph obj's underlying member method code with example usage: obj.create_tuple_store(train_graph, only_one_hop) without return types