docs: def swap_gain(mapping, node_id1, mapping_id1, node_id2, mapping_id2, weight_dict, match_num):
      """
      Compute the triple match number gain from the swapping
      Arguments:
      mapping: current node mapping list
      node_id1: node 1 index in AMR 1
      mapping_id1: the node index in AMR 2 node 1 maps to (in the current mapping)
      node_id2: node 2 index in AMR 1
      mapping_id2: the node index in AMR 2 node 2 maps to (in the current mapping)
      weight_dict: weight dictionary
      match_num: the original matching triple number
      Returns:
      the gain number (might be negative)
  
      """
      new_mapping_list = mapping[:]
      # Before swapping, node_id1 maps to mapping_id1, and node_id2 maps to mapping_id2
      # After swapping, node_id1 maps to mapping_id2 and node_id2 maps to mapping_id1
      new_mapping_list[node_id1] = mapping_id2
      new_mapping_list[node_id2] = mapping_id1
      if tuple(new_mapping_list) in match_triple_dict:
          return match_triple_dict[tuple(new_mapping_list)] - match_num
      gain = 0
      new_mapping1 = (node_id1, mapping_id2)
      new_mapping2 = (node_id2, mapping_id1)
      old_mapping1 = (node_id1, mapping_id1)
      old_mapping2 = (node_id2, mapping_id2)
      if node_id1 > node_id2:
          new_mapping2 = (node_id1, mapping_id2)
          new_mapping1 = (node_id2, mapping_id1)
          old_mapping1 = (node_id2, mapping_id2)
          old_mapping2 = (node_id1, mapping_id1)
      if new_mapping1 in weight_dict:
          for key in weight_dict[new_mapping1]:
              if key == -1:
                  gain += weight_dict[new_mapping1][-1]
              elif new_mapping_list[key[0]] == key[1]:
                  gain += weight_dict[new_mapping1][key]
      if new_mapping2 in weight_dict:
          for key in weight_dict[new_mapping2]:
              if key == -1:
                  gain += weight_dict[new_mapping2][-1]
              # to avoid duplicate
              elif key[0] == node_id1:
                  continue
              elif new_mapping_list[key[0]] == key[1]:
                  gain += weight_dict[new_mapping2][key]
      if old_mapping1 in weight_dict:
          for key in weight_dict[old_mapping1]:
              if key == -1:
                  gain -= weight_dict[old_mapping1][-1]
              elif mapping[key[0]] == key[1]:
                  gain -= weight_dict[old_mapping1][key]
      if old_mapping2 in weight_dict:
          for key in weight_dict[old_mapping2]:
              if key == -1:
                  gain -= weight_dict[old_mapping2][-1]
              # to avoid duplicate
              elif key[0] == node_id1:
                  continue
              elif mapping[key[0]] == key[1]:
                  gain -= weight_dict[old_mapping2][key]
      match_triple_dict[tuple(new_mapping_list)] = match_num + gain
      return gain