class_docstr: Repurpose a dataset for link prediction task.
  
  The created dataset will include data needed for link prediction.
  Currently it only supports homogeneous graphs.
  It will keep only the first graph in the provided dataset and
  generate train/val/test edges according to the given split ratio,
  and the correspondent negative edges based on the neg_ratio. The generated
  edges will be cached to disk for fast re-loading. If the provided split ratio
  differs from the cached one, it will re-process the dataset properly.
  
  Parameters
  ----------
  dataset : DGLDataset
      The dataset to be converted.
  split_ratio : (float, float, float), optional
      Split ratios for training, validation and test sets. Must sum to one.
  neg_ratio : int, optional
      Indicate how much negative samples to be sampled
      The number of the negative samples will be equal or less than neg_ratio * num_positive_edges.
  
  Attributes
  -------
  feat_size: int
      The size of the feature dimension in the graph
  train_graph: DGLGraph
      The DGLGraph for training
  val_edges: Tuple[Tuple[Tensor, Tensor], Tuple[Tensor, Tensor]]
      The validation set edges, encoded as
      ((positive_edge_src, positive_edge_dst), (negative_edge_src, negative_edge_dst))
  test_edges: Tuple[Tuple[Tensor, Tensor], Tuple[Tensor, Tensor]]
      The test set edges, encoded as
      ((positive_edge_src, positive_edge_dst), (negative_edge_src, negative_edge_dst))
  
  Examples
  --------
  >>> ds = dgl.data.CoraGraphDataset()
  >>> print(ds)
  Dataset("cora_v2", num_graphs=1, save_path=...)
  >>> new_ds = dgl.data.AsLinkPredDataset(ds, [0.8, 0.1, 0.1])
  >>> print(new_ds)
  Dataset("cora_v2-as-linkpred", num_graphs=1, save_path=/home/ubuntu/.dgl/cora_v2-as-linkpred)
  >>> print(hasattr(new_ds, "test_edges"))
  True
class_docstr_tok: ["Repurpose","a","dataset","for","link","prediction","task",".","The","created","dataset","will","include","data","needed","for","link","prediction",".","Currently","it","only","supports","homogeneous","graphs",".","It","will","keep","only","the","first","graph","in","the","provided","dataset","and","generate","train\/val\/test","edges","according","to","the","given","split","ratio",",","and","the","correspondent","negative","edges","based","on","the","neg_ratio",".","The","generated","edges","will","be","cached","to","disk","for","fast","re-loading",".","If","the","provided","split","ratio","differs","from","the","cached","one",",","it","will","re-process","the","dataset","properly",".","Parameters","--","--","--","--","--","dataset",":","DGLDataset","The","dataset","to","be","converted",".","split_ratio",":","(","float",",","float",",","float",")",",","optional","Split","ratios","for","training",",","validation","and","test","sets",".","Must","sum","to","one",".","neg_ratio",":","int",",","optional","Indicate","how","much","negative","samples","to","be","sampled","The","number","of","the","negative","samples","will","be","equal","or","less","than","neg_ratio","*","num_positive_edges",".","Attributes","--","--","--","-","feat_size",":","int","The","size","of","the","feature","dimension","in","the","graph","train_graph",":","DGLGraph","The","DGLGraph","for","training","val_edges",":","Tuple","[","Tuple","[","Tensor",",","Tensor","]",",","Tuple","[","Tensor",",","Tensor","]","]","The","validation","set","edges",",","encoded","as","(","(","positive_edge_src",",","positive_edge_dst",")",",","(","negative_edge_src",",","negative_edge_dst",")",")","test_edges",":","Tuple","[","Tuple","[","Tensor",",","Tensor","]",",","Tuple","[","Tensor",",","Tensor","]","]","The","test","set","edges",",","encoded","as","(","(","positive_edge_src",",","positive_edge_dst",")",",","(","negative_edge_src",",","negative_edge_dst",")",")","Examples","--","--","--","--",">",">",">","ds","=","dgl.data.CoraGraphDataset","(",")",">",">",">","print","(","ds",")","Dataset","(","``","cora_v2","''",",","num_graphs=1",",","save_path=","...",")",">",">",">","new_ds","=","dgl.data.AsLinkPredDataset","(","ds",",","[","0.8",",","0.1",",","0.1","]",")",">",">",">","print","(","new_ds",")","Dataset","(","``","cora_v2-as-linkpred","''",",","num_graphs=1",",","save_path=\/home\/ubuntu\/.dgl\/cora_v2-as-linkpred",")",">",">",">","print","(","hasattr","(","new_ds",",","``","test_edges","''",")",")","True"]
code: def __init__(self, dataset, split_ratio=None, neg_ratio=3, **kwargs):
      self.g = dataset[0]
      self.num_nodes = self.g.num_nodes()
      self.dataset = dataset
      self.split_ratio = split_ratio
      self.neg_ratio = neg_ratio
      super().__init__(
          dataset.name + "-as-linkpred",
          hash_key=(neg_ratio, split_ratio, dataset.name, "linkpred"),
          **kwargs,
      )
  
imports: import json
  import os
  import numpy
  from ..None import backend
  from ..base import DGLError
  from ..convert import graph
  from ..sampling.negative import _calc_redundancy
  from .None import utils
  from .dgl_dataset import DGLDataset
label_desc: Use image node_id 1 to create a new AsLinkPredDataset object from inherited base classes: DGLDataset with example: obj = AsLinkPredDataset(dataset, split_ratio, neg_ratio)