def move_gain(mapping, node_id, old_id, new_id, weight_dict, match_num):
<EOL>new_mapping = (node_id, new_id)<EOL>old_mapping = (node_id, old_id)<EOL>new_mapping_list = mapping[:]<EOL>new_mapping_list[node_id] = new_id<EOL>if tuple(new_mapping_list) in match_triple_dict:<EOL><INDENT>return match_triple_dict[tuple(new_mapping_list)] - match_num<EOL><DEDENT>gain = <NUM_LIT:0><EOL>if new_mapping in weight_dict:<EOL><INDENT>for key in weight_dict[new_mapping]:<EOL><INDENT>if key == -<NUM_LIT:1>:<EOL><INDENT>gain += weight_dict[new_mapping][-<NUM_LIT:1>]<EOL><DEDENT>elif new_mapping_list[key[<NUM_LIT:0>]] == key[<NUM_LIT:1>]:<EOL><INDENT>gain += weight_dict[new_mapping][key]<EOL><DEDENT><DEDENT><DEDENT>if old_mapping in weight_dict:<EOL><INDENT>for k in weight_dict[old_mapping]:<EOL><INDENT>if k == -<NUM_LIT:1>:<EOL><INDENT>gain -= weight_dict[old_mapping][-<NUM_LIT:1>]<EOL><DEDENT>elif mapping[k[<NUM_LIT:0>]] == k[<NUM_LIT:1>]:<EOL><INDENT>gain -= weight_dict[old_mapping][k]<EOL><DEDENT><DEDENT><DEDENT>match_triple_dict[tuple(new_mapping_list)] = match_num + gain<EOL>return gain<EOL>
Compute the triple match number gain from the move operation
Arguments:
    mapping: current node mapping
    node_id: remapped node in AMR 1
    old_id: original node id in AMR 2 to which node_id is mapped
    new_id: new node in to which node_id is mapped
    weight_dict: weight dictionary
    match_num: the original triple matching number
Returns:
    the triple match gain number (might be negative)