def _construct_token_subtree(self, graph_to_output_example, token,
                               cur_node_id, token_root_name):
    # pylint: disable=line-too-long
    """Construct the token subtree in a AST path.

    We create a node for each subtoken in the token, all subtokens are connected
    to the next subtoken via the 'NEXT_SUBTOKEN' edge. All subtokens are
    connected to the token root node via the 'SUBTOKEN' edge. See the draw.io
    figure mentioned in the class doc for the visualization.

    Args:
      graph_to_output_example: A GraphToOutputExample instance.
      token: Starting or ending token in the AST path.
      cur_node_id: Next available node id.
      token_root_name: Node type and label for the token root node.

    Returns:
      A tuple of graph_to_output_example, cur_node_id, token_node_id.
      graph_to_output_example is updated with the token subtree, cur_node_id is
      the next available node id after all the token subtree nodes are added,
      and token_node_id is the node id of the root token node.
    """
    subtokens = token.split('|')
    subtoken_node_ids = []
    prev_subtoken_id = -1
    # Create a node each subtoken.
    for subtoken in subtokens:
      graph_to_output_example.add_node(cur_node_id, 'SUBTOKEN', subtoken)
      subtoken_node_ids.append(cur_node_id)
      # Connects to the previous subtoken node
      if prev_subtoken_id != -1:
        graph_to_output_example.add_edge(prev_subtoken_id, cur_node_id,
                                         'NEXT_SUBTOKEN')
      prev_subtoken_id = cur_node_id
      cur_node_id += 1

    # Add a root node for the token subtree.
    graph_to_output_example.add_node(cur_node_id, token_root_name,
                                     token_root_name)
    token_node_id = cur_node_id
    cur_node_id += 1
    # Connect all subtoken nodes to the token subtree root node.
    for node_id in subtoken_node_ids:
      graph_to_output_example.add_edge(token_node_id, node_id, 'SUBTOKEN')

    return graph_to_output_example, cur_node_id, token_node_id