class_docstr: Load knowledge graph data from files
  
  Args:
      path (str):
          Directory of triplet dataset.
      data_name (str):
          The folder name of triplet dataset.
      hrt_mode (str, optional):
          The order of head, relation and tail per line in triplet file.
          Choices: 'hrt', 'htr', 'trh', 'thr', 'rht', 'rth'.
      kv_mode (str, optional):
          The order of string names and ids in dictionary files.
          'kv' denotes entity_name/relation_name, id.
      train_file (str, optional):
          Filename of training data.
      valid_file (str, optional):
          Filename of validation data.
      test_file (str, optional):
          Filename of test data.
      ent_file (str, optional):
          Filename of entity_to_id dictionary.
      rel_file (str, optional):
          Filename of relation_to_id dictionary.
      delimiter (char, optional):
          The delimiter in files.
      map_to_id (bool, optional):
          Whether to map loaded elements into int ids.
      load_dict (bool, optional):
          Whether to load dictionaries from files.
      skip_head (bool, optional):
          Whether to ignore the first line of dictionary files.
class_docstr_tok: ["Load","knowledge","graph","data","from","files","Args",":","path","(","str",")",":","Directory","of","triplet","dataset",".","data_name","(","str",")",":","The","folder","name","of","triplet","dataset",".","hrt_mode","(","str",",","optional",")",":","The","order","of","head",",","relation","and","tail","per","line","in","triplet","file",".","Choices",":","'hrt","'",",","'htr","'",",","'trh","'",",","'thr","'",",","'rht","'",",","'rth","'",".","kv_mode","(","str",",","optional",")",":","The","order","of","string","names","and","ids","in","dictionary","files",".","'kv","'","denotes","entity_name\/relation_name",",","id",".","train_file","(","str",",","optional",")",":","Filename","of","training","data",".","valid_file","(","str",",","optional",")",":","Filename","of","validation","data",".","test_file","(","str",",","optional",")",":","Filename","of","test","data",".","ent_file","(","str",",","optional",")",":","Filename","of","entity_to_id","dictionary",".","rel_file","(","str",",","optional",")",":","Filename","of","relation_to_id","dictionary",".","delimiter","(","char",",","optional",")",":","The","delimiter","in","files",".","map_to_id","(","bool",",","optional",")",":","Whether","to","map","loaded","elements","into","int","ids",".","load_dict","(","bool",",","optional",")",":","Whether","to","load","dictionaries","from","files",".","skip_head","(","bool",",","optional",")",":","Whether","to","ignore","the","first","line","of","dictionary","files","."]
code: def create_dict(self, ent_path, rel_path):
      while not (os.path.exists(ent_path) and os.path.exists(rel_path)):
          if dist.get_rank() == 0:
              data = []
              for file in self._data_list:
                  path = os.path.join(self._path, file)
                  data.append(
                      self.load_triplet(
                          path,
                          self._hrt,
                          self._delimiter,
                          self._skip_head,
                      )
                  )
              all_ents = set()
              all_rels = set()
              for triplets in data:
                  for h, r, t in triplets:
                      all_ents.add(h)
                      all_ents.add(t)
                      all_rels.add(r)
              self._ent_dict = dict(
                  [(x, i) for i, x in enumerate(all_ents)]
              )
              self._rel_dict = dict(
                  [(x, i) for i, x in enumerate(all_rels)]
              )
              if not os.path.exists(ent_path):
                  with open(ent_path, "w") as fp:
                      for k, v in self._ent_dict.items():
                          fp.write("{}\t{}\n".format(k, v))
              if not os.path.exists(rel_path):
                  with open(rel_path, "w") as fp:
                      for k, v in self._rel_dict.items():
                          fp.write("{}\t{}\n".format(k, v))
          else:
              time.sleep(1)
  
imports: import os
  import time
  import numpy
  import paddle.distributed
  from dataset.trigraph import TriGraph
  from utils import timer_wrapper
label_desc: Use image node_id 5 for calling the TripletDataset obj's underlying member method code with example usage: obj.create_dict(ent_path, rel_path) without return types