class_docstr: A Graphbolt dataset for legacy DGLDataset.
class_docstr_tok: ["A","Graphbolt","dataset","for","legacy","DGLDataset","."]
code: def _init_as_heterogeneous_node_pred(self, legacy: DGLDataset):
      def _init_item_set_dict(idx, labels):
          item_set_dict = {}
          for key in idx.keys():
              item_set = ItemSet(
                  (idx[key], labels[key][idx[key]]),
                  names=("seed_nodes", "labels"),
              )
              item_set_dict[key] = item_set
          return ItemSetDict(item_set_dict)
  
      # OGB Dataset has the idx split.
      if hasattr(legacy, "get_idx_split"):
          graph, labels = legacy[0]
          split_idx = legacy.get_idx_split()
  
          # Initialize tasks.
          tasks = []
          metadata = {
              "num_classes": legacy.num_classes,
              "name": "node_classification",
          }
          train_set = _init_item_set_dict(split_idx["train"], labels)
          validation_set = _init_item_set_dict(
              split_idx["valid"], labels
          )
          test_set = _init_item_set_dict(split_idx["test"], labels)
          task = OnDiskTask(
              metadata, train_set, validation_set, test_set
          )
          tasks.append(task)
          self._tasks = tasks
  
          item_set_dict = {}
          for ntype in graph.ntypes:
              item_set = ItemSet(
                  graph.num_nodes(ntype), names="seed_nodes"
              )
              item_set_dict[ntype] = item_set
          self._all_nodes_set = ItemSetDict(item_set_dict)
  
          features = {}
          for ntype in graph.ntypes:
              for name in graph.nodes[ntype].data.keys():
                  tensor = graph.nodes[ntype].data[name]
                  if tensor.dim() == 1:
                      tensor = tensor.view(-1, 1)
                  features[("node", ntype, name)] = TorchBasedFeature(
                      tensor
                  )
          for etype in graph.canonical_etypes:
              for name in graph.edges[etype].data.keys():
                  tensor = graph.edges[etype].data[name]
                  if tensor.dim() == 1:
                      tensor = tensor.view(-1, 1)
                  gb_etype = etype_tuple_to_str(etype)
                  features[
                      ("edge", gb_etype, name)
                  ] = TorchBasedFeature(tensor)
          self._feature = BasicFeatureStore(features)
          self._graph = from_dglgraph(graph, is_homogeneous=False)
          self._dataset_name = legacy.name
      else:
          raise NotImplementedError(
              "Only support heterogeneous ogn node pred dataset"
          )
  
file_path: dgl/python/dgl/graphbolt/impl/legacy_dataset.py
imports: from typing import List, Union
  from dgl.data import AsNodePredDataset, DGLDataset
  from ..base import etype_tuple_to_str
  from ..dataset import Dataset, Task
  from ..itemset import ItemSet, ItemSetDict
  from ..sampling_graph import SamplingGraph
  from .basic_feature_store import BasicFeatureStore
  from .fused_csc_sampling_graph import from_dglgraph
  from .ondisk_dataset import OnDiskTask
  from .torch_based_feature_store import TorchBasedFeature
label_desc: Use image node_id 2 for calling the LegacyDataset obj's underlying member method code with example usage: obj._init_as_heterogeneous_node_pred(legacy) and returns: ItemSetDict