code: def gen_train_facts(data_file_name, truth_dir):
      fact_file_name = data_file_name[data_file_name.find("train_") :]
      fact_file_name = os.path.join(
          truth_dir, fact_file_name.replace(".json", ".fact")
      )
  
      if os.path.exists(fact_file_name):
          fact_in_train = set([])
          triples = json.load(open(fact_file_name))
          for x in triples:
              fact_in_train.add(tuple(x))
          return fact_in_train
  
      fact_in_train = set([])
      ori_data = json.load(open(data_file_name))
      for data in ori_data:
          vertexSet = data["vertexSet"]
          for label in data["labels"]:
              rel = label["r"]
              for n1 in vertexSet[label["h"]]:
                  for n2 in vertexSet[label["t"]]:
                      fact_in_train.add((n1["name"], n2["name"], rel))
  
      json.dump(list(fact_in_train), open(fact_file_name, "w"))
  
      return fact_in_train
  
imports: import os
  import os.path
  import json
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: gen_train_facts(data_file_name, truth_dir) and returns: fact_in_train, fact_in_train