class_docstr: Class for constituency graph construction.
  
  ...
  
  Attributes
  ----------
  embedding_styles : (dict)
      Specify embedding styles including ``single_token_item``, ``emb_strategy``,
      ``num_rnn_layers``, ``bert_model_name`` and ``bert_lower_case``.
  
  vocab: (set, optional)
      Vocabulary including all words appeared in graphs.
  
  Methods
  -------
  
  topology(raw_text_data, nlp_processor, merge_strategy=None, edge_strategy=None)
      Generate graph structure with nlp parser like ``CoreNLP`` etc.
  
  _construct_static_graph(parsed_object, sub_sentence_id, edge_strategy=None)
      Construct a single static graph from a single sentence,
      to be called by ``topology`` function.
  
  _graph_connect(nx_graph_list, merge_strategy=None)
      Construct a merged graph from a list of graphs, to be called by ``topology`` function.
  
  embedding(node_attributes, edge_attributes)
      Generate node/edge embeddings from node/edge attributes through an embedding layer.
  
  forward(raw_text_data, nlp_parser)
      Generate graph topology and embeddings.
docstr: Parameters
  ----------
  graph_list : list
      A graph list to be merged
  
  bisequential_link : bool
      whether add bi-direnctional links between word nodes
  
  reformalize : bool
      If true, separate word nodes and non-terminal nodes in ``graph.node_attributes``
      and put word nodes in the front position
  
  Returns
  -------
  GraphData
      A customized graph data structure
docstr_tok: ["Parameters","--","--","--","--","--","graph_list",":","list","A","graph","list","to","be","merged","bisequential_link",":","bool","whether","add","bi-direnctional","links","between","word","nodes","reformalize",":","bool","If","true",",","separate","word","nodes","and","non-terminal","nodes","in","``","graph.node_attributes","``","and","put","word","nodes","in","the","front","position","Returns","--","--","--","-","GraphData","A","customized","graph","data","structure"]
code: def _graph_connect(
      cls,
      graph_list,
      merge_strategy=None,
      bisequential_link=True,
      reformalize=True,
  ):
      """
      Parameters
      ----------
      graph_list : list
          A graph list to be merged
  
      bisequential_link : bool
          whether add bi-direnctional links between word nodes
  
      reformalize : bool
          If true, separate word nodes and non-terminal nodes in ``graph.node_attributes``
          and put word nodes in the front position
  
      Returns
      -------
      GraphData
          A customized graph data structure
      """
      _len_graph_ = len(graph_list)
      # if only one sentence included, we do not need to merge the graph.
      if _len_graph_ > 1:
          merged_graph = GraphData()
          for index in range(_len_graph_):
              # len_merged_graph = merged_graph.get_node_num()
  
              graph_i_nodes_attributes = []
              for list_item in graph_list[index].node_attributes:
                  graph_i_nodes_attributes.append(list_item)
              merged_graph.node_attributes.extend(
                  graph_i_nodes_attributes
              )
  
          _cnt_edge_num = 0
          for g_idx in range(_len_graph_):
              tmp_edges = graph_list[g_idx].get_all_edges()
              current_node_num = graph_list[g_idx].get_node_num()
              for _edge in tmp_edges:
                  merged_graph.add_edge(
                      _edge[0] + _cnt_edge_num, _edge[1] + _cnt_edge_num
                  )
              _cnt_edge_num += current_node_num
  
          for index in range(_len_graph_ - 1):
              # get head node
              head_node = -1
              for idx, node_attr_item in enumerate(
                  merged_graph.node_attributes
              ):
                  if (
                      node_attr_item["sentence_id"] == index + 1
                      and node_attr_item["type"] == 0
                      and node_attr_item["head"] is True
                  ):
                      head_node = idx
              # get tail node
              tail_node = -1
              for idx, node_attr_item in enumerate(
                  merged_graph.node_attributes
              ):
                  if (
                      node_attr_item["sentence_id"] == index
                      and node_attr_item["type"] == 0
                      and node_attr_item["tail"] is True
                  ):
                      tail_node = idx
              merged_graph.add_edge(tail_node, head_node)
              if bisequential_link:
                  merged_graph.add_edge(head_node, tail_node)
      else:
          merged_graph = graph_list[0]
      if reformalize:
          new_list_for_nodes = copy.deepcopy(
              merged_graph.node_attributes
          )
  
          list_for_word_nodes = []
          list_for_non_ternimal_nodes = []
          for i_0, i_1 in enumerate(new_list_for_nodes):
              if i_1["type"] == 0:
                  list_for_word_nodes.append((i_0, i_1))
              else:
                  list_for_non_ternimal_nodes.append((i_0, i_1))
  
          node_id_map = {}
          cnt = 0
          merged_graph.node_attributes.clear()
          for item in list_for_word_nodes:
              merged_graph.node_attributes.append(item[1])
              node_id_map[item[0]] = cnt
              cnt += 1
          for item in list_for_non_ternimal_nodes:
              merged_graph.node_attributes.append(item[1])
              node_id_map[item[0]] = cnt
              cnt += 1
          for i in range(merged_graph.get_edge_num()):
              merged_graph._edge_indices.src[i] = node_id_map[
                  merged_graph._edge_indices.src[i]
              ]
              merged_graph._edge_indices.tgt[i] = node_id_map[
                  merged_graph._edge_indices.tgt[i]
              ]
      return merged_graph
  
file_path: graph4nlp/graph4nlp/pytorch/modules/graph_construction/constituency_graph_construction.py
imports: import copy
  import json
  from pythonds.basic.stack import Stack
  from graph4nlp.pytorch.data.data import GraphData
  from .base import StaticGraphConstructionBase
  from .utils import CORENLP_TIMEOUT_SIGNATURE
label_desc: Use image node_id 5 for calling the ConstituencyBasedGraphConstruction obj's underlying member method code with example usage: obj._graph_connect(cls, graph_list, merge_strategy, bisequential_link, reformalize) and returns: merged_graph