class_docstr: Read a knowledge graph to memory
class_docstr_tok: ["Read","a","knowledge","graph","to","memory"]
docstr: Find and store all paths from all entities upto max_path_length.
docstr_tok: ["Find","and","store","all","paths","from","all","entities","upto","max_path_length","."]
code: def store_paths(self):
      """Find and store all paths from all entities upto max_path_length."""
      self.paths = [
          defaultdict(list) for _ in range(self.max_path_length)
      ]
      # Add all paths of length 1
      for e in self.kg_data:
          self.paths[0][e] = [
              "%d %d" % (r, e2)
              for e2 in self.kg_data[e]
              for r in self.kg_data[e][e2]
          ]
      # Add all paths of length > 1
      for i in range(1, self.max_path_length):
          for e in self.kg_data:
              for path in self.paths[i - 1][e]:
                  all_prev_e = map(int, path.strip().split(" ")[1::2])
                  last_e = all_prev_e[-1]
                  # last_r = int(path.strip().split(" ")[-2])
                  if last_e not in self.kg_data:
                      continue
                  new_paths = [
                      path + " %d %d" % (r, e2)
                      for e2 in self.kg_data[last_e]
                      for r in self.kg_data[last_e][e2]
                      if e2 not in all_prev_e
                  ]
                  self.paths[i][e] += new_paths
  
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 7 for calling the Graph obj's underlying member method code with example usage: obj.store_paths() without return types