class_docstr:     Line based graph construction class
  Parameters
  ----------
  embedding_style: dict
      Specify embedding styles including ``word_emb_type``, ``node_edge_level_emb_type``
      and ``graph_level_emb_type``.
  vocab: VocabModel
      Vocabulary including all words appeared in graphs.
class_docstr_tok: ["Line","based","graph","construction","class","Parameters","--","--","--","--","--","embedding_style",":","dict","Specify","embedding","styles","including","``","word_emb_type","``",",","``","node_edge_level_emb_type","``","and","``","graph_level_emb_type","``",".","vocab",":","VocabModel","Vocabulary","including","all","words","appeared","in","graphs","."]
docstr:     This method will merge the sub-graphs into one graph.
  Parameters
  ----------
  nx_graph_list: list[GraphData]
      The list of all sub-graphs.
  merge_strategy: None or str, option=[None, "tailhead", "sequential", "user_define"]
      Strategy to merge sub-graphs into one graph
      ``None``: It will be the default option. We will do as ``"tailhead"``.
      ``"tailhead"``: Link the sub-graph  ``i``'s tail node with ``i+1``'s head node
      ``"user_define"``: We will give this option to the user. User can override
      this method to define your merge strategy.
  Returns
  -------
  joint_graph: GraphData
      The merged graph structure.
docstr_tok: ["This","method","will","merge","the","sub-graphs","into","one","graph",".","Parameters","--","--","--","--","--","nx_graph_list",":","list","[","GraphData","]","The","list","of","all","sub-graphs",".","merge_strategy",":","None","or","str",",","option=","[","None",",","``","tailhead","''",",","``","sequential","''",",","``","user_define","''","]","Strategy","to","merge","sub-graphs","into","one","graph","``","None","``",":","It","will","be","the","default","option",".","We","will","do","as","``","``","tailhead","''","``",".","``","``","tailhead","''","``",":","Link","the","sub-graph","``","i","``","'s","tail","node","with","``","i+1","``","'s","head","node","``","``","user_define","''","``",":","We","will","give","this","option","to","the","user",".","User","can","override","this","method","to","define","your","merge","strategy",".","Returns","--","--","--","-","joint_graph",":","GraphData","The","merged","graph","structure","."]
code: def _graph_connect(cls, nx_graph_list, merge_strategy=None):
      """
          This method will merge the sub-graphs into one graph.
      Parameters
      ----------
      nx_graph_list: list[GraphData]
          The list of all sub-graphs.
      merge_strategy: None or str, option=[None, "tailhead", "sequential", "user_define"]
          Strategy to merge sub-graphs into one graph
          ``None``: It will be the default option. We will do as ``"tailhead"``.
          ``"tailhead"``: Link the sub-graph  ``i``'s tail node with ``i+1``'s head node
          ``"user_define"``: We will give this option to the user. User can override
          this method to define your merge strategy.
      Returns
      -------
      joint_graph: GraphData
          The merged graph structure.
      """
      if cls.verbose > 0:
          print("sub_graph print")
          for i, s_g in enumerate(nx_graph_list):
              print("-------------------------")
              print("sub-graph: {}".format(i))
              print("node_num: {}".format(s_g.get_node_num()))
              for i in range(s_g.get_node_num()):
                  print(s_g.get_node_attrs(i))
              print("edge_num: {}".format(s_g.get_edge_num()))
              print(s_g.get_all_edges())
              for i in range(s_g.get_edge_num()):
                  print(i, s_g.edge_attributes[i])
          print("*************************************")
      if len(nx_graph_list) == 1:
          return nx_graph_list[0]
      elif len(nx_graph_list) == 0:
          raise RuntimeError("There is no graph needed to merge.")
      node_num_list = [s_g.get_node_num() for s_g in nx_graph_list]
      node_num = sum(node_num_list)
      g = GraphData()
      g.add_nodes(node_num)
      node_idx_off = 0
  
      # copy edges
      for s_g in nx_graph_list:
          for edge in s_g.get_all_edges():
              src, tgt = edge
              edge_idx_old = s_g.edge_ids(src, tgt)[0]
              g.add_edge(src + node_idx_off, tgt + node_idx_off)
              edge_idx_new = g.edge_ids(
                  src + node_idx_off, tgt + node_idx_off
              )[0]
              if cls.verbose > 0:
                  print(edge_idx_new, edge_idx_old)
                  print(s_g.edge_attributes[edge_idx_old], "--------")
              g.edge_attributes[edge_idx_new] = copy.deepcopy(
                  s_g.edge_attributes[edge_idx_old]
              )
          tmp = {}
          for key, value in s_g.node_attributes.items():
              tmp[key + node_idx_off] = copy.deepcopy(value)
          g.node_attributes.update(tmp)
          node_idx_off += s_g.get_node_num()
  
      headtail_list = []
  
      head = -1
      tail = -1
  
      node_idx_off = 0
      for i in range(len(nx_graph_list)):
          for node_idx, node_attrs in nx_graph_list[
              i
          ].node_attributes.items():
              if node_attrs["head"] is True:
                  head = node_idx + node_idx_off
              if node_attrs["tail"] is True:
                  tail = node_idx + node_idx_off
          assert head != -1
          assert tail != -1
          headtail_list.append((head, tail))
          head = -1
          tail = -1
          node_idx_off += node_num_list[i]
  
      head_g = headtail_list[0][0]
      tail_g = headtail_list[-1][1]
  
      if merge_strategy is None or merge_strategy == "tailhead":
          src_list = []
          tgt_list = []
  
          for i in range(len(headtail_list) - 1):
              src_list.append(headtail_list[i][1])
              tgt_list.append(headtail_list[i + 1][0])
          if cls.verbose > 0:
              print("merged edges")
              print("src list:", src_list)
              print("tgt list:", tgt_list)
          g.add_edges(src_list, tgt_list)
  
      elif merge_strategy == "re_occurrences":
          token_list = [
              g.node_attributes[node_id]["token"]
              for node_id in g.node_attributes
          ]
          token_count = dict(Counter(token_list))
          repeat_token = [
              key for key, value in token_count.items() if value > 1
          ]
          re_occ_pair = []
          for token in repeat_token:
              re_occ_list = [
                  i for i, v in enumerate(token_list) if v == token
              ]
              re_occ_pair.extend(
                  list(itertools.combinations(re_occ_list, 2))
              )
          for pair in re_occ_pair:
              g.add_edge(pair[0], pair[1])
              g.add_edge(pair[1], pair[0])
      else:
          raise NotImplementedError()
  
      for node_idx, node_attrs in g.node_attributes.items():
          node_attrs["head"] = node_idx == head_g
          node_attrs["tail"] = node_idx == tail_g
  
      if cls.verbose > 0:
          print("-----------------------------")
          print("merged graph")
          print("node_num: {}".format(g.get_node_num()))
          for i in range(g.get_node_num()):
              print(g.get_node_attrs(i))
          print("edge_num: {}".format(g.get_edge_num()))
          print(g.get_all_edges())
          for i in range(g.get_edge_num()):
              print(i, g.edge_attributes[i])
      return g
  
file_path: graph4nlp/examples/pytorch/name_entity_recognition/dependency_graph_construction_without_tokenize.py
imports: import copy
  import itertools
  import json
  from collections import Counter
  from graph4nlp.pytorch.data.data import GraphData
  from graph4nlp.pytorch.modules.graph_construction.base import StaticGraphConstructionBase
label_desc: Use image node_id 6 for calling the DependencyBasedGraphConstruction_without_tokenizer obj's underlying member method code with example usage: obj._graph_connect(cls, nx_graph_list, merge_strategy) and returns: g, nx_graph_list