class_docstr: Read a knowledge graph to memory
class_docstr_tok: ["Read","a","knowledge","graph","to","memory"]
docstr: Init Graph class.
docstr_tok: ["Init","Graph","class","."]
code: def __init__(
      self,
      kg_file,
      entity_vocab=False,
      relation_vocab=False,
      add_reverse_graph=False,
      add_inverse_edge=False,
      mode="train",
      max_path_length=None,
      **kwargs,
  ):
      """Init Graph class."""
      del kwargs
      if add_reverse_graph and add_inverse_edge:
          raise ValueError(
              "Only one of add_reverse_graph or add_inverse_edge should be used"
          )
      self._raw_kg_file = kg_file
      self.add_reverse_graph = add_reverse_graph
      self.add_inverse_edge = add_inverse_edge
      if add_inverse_edge:
          self.inverse_relation_prefix = "INVERSE:"
      # vocab maps from name to integer id
      if entity_vocab:
          self.entity_vocab = entity_vocab
      else:
          self.entity_vocab = {}
      if relation_vocab:
          self.relation_vocab = relation_vocab
      else:
          self.relation_vocab = {}
      self.ent_vocab_size = len(self.entity_vocab)
      self.rel_vocab_size = len(self.relation_vocab)
      self._num_edges = 0
  
      self.kg_data = defaultdict(dict)
      self.next_edges = defaultdict(set)
      if self.add_reverse_graph:
          self.reverse_kg_data = defaultdict(dict)
          self.reverse_next_edges = defaultdict(set)
      self.entity_pad_token = "ePAD"
      self.relation_pad_token = "rPAD"
      # self.no_op_relation = "NO_OP"
      self.max_kg_relations = None
      # self.max_ent_sampled = max_ent_sampled
      self.mode = mode
      self.read_graph(mode)
      # inverse vocab maps from integer id to name
      self.inverse_relation_vocab = {
          v: k for k, v in self.relation_vocab.iteritems()
      }
      self.inverse_entity_vocab = {
          v: k for k, v in self.entity_vocab.iteritems()
      }
      if mode == "train":
          self.all_entities = set(self.entity_vocab.values())
          self.max_neighbors = self._max_neighbors()
      self.all_reachable_e2 = defaultdict(set)
      self.all_reachable_e2_reverse = defaultdict(set)
      self.tuple_store = []
      self.create_tuple_store()
      logging.debug("Graph data read")
      logging.info("Entity vocab: %d", self.ent_vocab_size)
      logging.info("Relation vocab: %d", self.rel_vocab_size)
      logging.info("Number of edges: %d", self._num_edges)
      self.max_path_length = max_path_length
  
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 1 to create a new Graph object from inherited base classes: object with example: obj = Graph(kg_file, entity_vocab, relation_vocab, add_reverse_graph, add_inverse_edge, mode, max_path_length)