class_docstr: Adapted from https://docs.dgl.ai/en/latest/_modules/dgl/data/chem/csv_dataset.html#CSVDataset
class_docstr_tok: ["Adapted","from","https",":","\/\/docs.dgl.ai\/en\/latest\/_modules\/dgl\/data\/chem\/csv_dataset.html","#","CSVDataset"]
code: def pre_process(self):
      processed_dir = osp.join(self.root, "processed")
      pre_processed_file_path = osp.join(
          processed_dir, "dgl_data_processed"
      )
  
      if osp.exists(pre_processed_file_path):
          self.graph, _ = load_graphs(pre_processed_file_path)
  
      else:
          ### check if the downloaded file exists
          if self.binary:
              # npz format
              has_necessary_file_simple = osp.exists(
                  osp.join(self.root, "raw", "data.npz")
              ) and (not self.is_hetero)
              has_necessary_file_hetero = (
                  osp.exists(
                      osp.join(self.root, "raw", "edge_index_dict.npz")
                  )
                  and self.is_hetero
              )
          else:
              # csv file
              has_necessary_file_simple = osp.exists(
                  osp.join(self.root, "raw", "edge.csv.gz")
              ) and (not self.is_hetero)
              has_necessary_file_hetero = (
                  osp.exists(
                      osp.join(
                          self.root, "raw", "triplet-type-list.csv.gz"
                      )
                  )
                  and self.is_hetero
              )
  
          has_necessary_file = (
              has_necessary_file_simple or has_necessary_file_hetero
          )
          if not has_necessary_file:
              url = self.meta_info["url"]
              if decide_download(url):
                  path = download_url(url, self.original_root)
                  extract_zip(path, self.original_root)
                  os.unlink(path)
                  # delete folder if there exists
                  try:
                      shutil.rmtree(self.root)
                  except:
                      pass
                  shutil.move(
                      osp.join(self.original_root, self.download_name),
                      self.root,
                  )
              else:
                  print("Stop download.")
                  exit(-1)
  
          raw_dir = osp.join(self.root, "raw")
  
          add_inverse_edge = (
              self.meta_info["add_inverse_edge"] == "True"
          )
  
          ### pre-process and save
          if self.meta_info["additional node files"] == "None":
              additional_node_files = []
          else:
              additional_node_files = self.meta_info[
                  "additional node files"
              ].split(",")
  
          if self.meta_info["additional edge files"] == "None":
              additional_edge_files = []
          else:
              additional_edge_files = self.meta_info[
                  "additional edge files"
              ].split(",")
  
          if self.is_hetero:
              graph = read_heterograph_dgl(
                  raw_dir,
                  add_inverse_edge=add_inverse_edge,
                  additional_node_files=additional_node_files,
                  additional_edge_files=additional_edge_files,
                  binary=self.binary,
              )[0]
          else:
              graph = read_graph_dgl(
                  raw_dir,
                  add_inverse_edge=add_inverse_edge,
                  additional_node_files=additional_node_files,
                  additional_edge_files=additional_edge_files,
                  binary=self.binary,
              )[0]
  
          print("Saving...")
          save_graphs(pre_processed_file_path, graph, {})
  
          self.graph, _ = load_graphs(pre_processed_file_path)
  
file_path: ogb/ogb/linkproppred/dataset_dgl.py
imports: import pandas
  import shutil, os
  import os.path
  import torch
  import numpy
  from dgl.data.utils import load_graphs, save_graphs, Subset
  import dgl
  from ogb.utils.url import decide_download, download_url, extract_zip
  from ogb.io.read_graph_dgl import read_graph_dgl, read_heterograph_dgl
  from ogb.utils.torch_util import replace_numpy_with_torchtensor
label_desc: Use image node_id 2 for calling the DglLinkPropPredDataset obj's underlying member method code with example usage: obj.pre_process() without return types