def compute_match(mapping, weight_dict):
<EOL>if veryVerbose:<EOL><INDENT>print("<STR_LIT>", file=DEBUG_LOG)<EOL>print(mapping, file=DEBUG_LOG)<EOL><DEDENT>if tuple(mapping) in match_triple_dict:<EOL><INDENT>if veryVerbose:<EOL><INDENT>print("<STR_LIT>", match_triple_dict[tuple(mapping)], file=DEBUG_LOG)<EOL><DEDENT>return match_triple_dict[tuple(mapping)]<EOL><DEDENT>match_num = <NUM_LIT:0><EOL>for i, m in enumerate(mapping):<EOL><INDENT>if m == -<NUM_LIT:1>:<EOL><INDENT>continue<EOL><DEDENT>current_node_pair = (i, m)<EOL>if current_node_pair not in weight_dict:<EOL><INDENT>continue<EOL><DEDENT>if veryVerbose:<EOL><INDENT>print("<STR_LIT>", current_node_pair, file=DEBUG_LOG)<EOL><DEDENT>for key in weight_dict[current_node_pair]:<EOL><INDENT>if key == -<NUM_LIT:1>:<EOL><INDENT>match_num += weight_dict[current_node_pair][key]<EOL>if veryVerbose:<EOL><INDENT>print("<STR_LIT>", weight_dict[current_node_pair][key], file=DEBUG_LOG)<EOL><DEDENT><DEDENT>elif key[<NUM_LIT:0>] < i:<EOL><INDENT>continue<EOL><DEDENT>elif mapping[key[<NUM_LIT:0>]] == key[<NUM_LIT:1>]:<EOL><INDENT>match_num += weight_dict[current_node_pair][key]<EOL>if veryVerbose:<EOL><INDENT>print("<STR_LIT>", key, weight_dict[current_node_pair][key], file=DEBUG_LOG)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if veryVerbose:<EOL><INDENT>print("<STR_LIT>", match_num, file=DEBUG_LOG)<EOL><DEDENT>match_triple_dict[tuple(mapping)] = match_num<EOL>return match_num<EOL>
Given a node mapping, compute match number based on weight_dict.
Args:
mappings: a list of node index in AMR 2. The ith element (value j) means node i in AMR 1 maps to node j in AMR 2.
Returns:
matching triple number
Complexity: O(m*n) , m is the node number of AMR 1, n is the node number of AMR 2