code: def build_graph(self):
      graph = dgl.DGLGraph()
      ent_len = len(self.raw_ent_text)
      rel_len = len(
          self.raw_rel
      )  # treat the repeated relation as different nodes, refer to the author's code
  
      graph.add_nodes(
          ent_len, {"type": torch.ones(ent_len) * NODE_TYPE["entity"]}
      )
      graph.add_nodes(1, {"type": torch.ones(1) * NODE_TYPE["root"]})
      graph.add_nodes(
          rel_len * 2,
          {"type": torch.ones(rel_len * 2) * NODE_TYPE["relation"]},
      )
      graph.add_edges(ent_len, torch.arange(ent_len))
      graph.add_edges(torch.arange(ent_len), ent_len)
      graph.add_edges(
          torch.arange(ent_len + 1 + rel_len * 2),
          torch.arange(ent_len + 1 + rel_len * 2),
      )
      adj_edges = []
      for i, r in enumerate(self.raw_rel):
          assert len(r) == 3, str(r)
          st, rt, ed = r
          st_ent, ed_ent = self.raw_ent_text.index(
              st
          ), self.raw_ent_text.index(ed)
          # according to the edge_softmax operator, we need to reverse the graph
          adj_edges.append([ent_len + 1 + 2 * i, st_ent])
          adj_edges.append([ed_ent, ent_len + 1 + 2 * i])
          adj_edges.append([ent_len + 1 + 2 * i + 1, ed_ent])
          adj_edges.append([st_ent, ent_len + 1 + 2 * i + 1])
  
      if len(adj_edges) > 0:
          graph.add_edges(*list(map(list, zip(*adj_edges))))
      return graph
  
imports: import json
  import pickle
  import random
  import dgl
  import numpy
  import torch
label_desc: Use image node_id 5 for calling the Example obj's underlying member method code with example usage: obj.build_graph() and returns: graph