Skip to content

Commit b4ea534

Browse files
committed
Working on s2matchdev.py
1 parent 9e7052b commit b4ea534

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

amr_suite/py3-Smatch-and-S2match/smatch/s2matchdev.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,28 +1046,50 @@ def main(arguments):
10461046
meta_available = bool(meta1['labels_dict'] and meta2['labels_dict'])
10471047

10481048
if -1 in best_mapping and meta_available:
1049-
nodes_unmapped = [f'{prefix1}{i}' for i, mapped_to in enumerate(best_mapping) if mapped_to == -1]
1049+
# finds nodes in AMR1, which were not mapped to any nodes in AMR2
1050+
nodes_unmapped = [f'{prefix1}{i}' for i, mapped_to in enumerate(best_mapping) if mapped_to == -1]
1051+
1052+
# returns 'MRPNode-i' if found in labels dict, else None
10501053
labels_dict = defaultdict(lambda: None, meta1['labels_dict']) # "0.0": "MRPNode-1"
1054+
1055+
# we need to reverse the dictionary to get structure labels instead of MRPNode-i
10511056
labels_dict_reversed = defaultdict(lambda: None, {v:k for k, v in labels_dict.items()}) # "MRPNode-1":"0.0"
1057+
1058+
# parent is the node next to the root, which contains the node in question
10521059
find_parent = lambda x: labels_dict['.'.join(x.split('.')[:2])] # find_parent("0.0.0") == "MRPNode-0"
1060+
1061+
# we find the parent node for all unlabeled nodes, except for the case when the parent node is the root
1062+
# because in this case (parent == root), we don't have any information as to how we should align it
10531063
nodes_with_parents = {node:find_parent(labels_dict_reversed[node])
10541064
for node in nodes_unmapped if find_parent(labels_dict_reversed[node]) != '0'} # except root
1055-
nodes_with_parents = {k:v for k, v in nodes_with_parents.items() if v is not None} # filter those with no parent found (should actually never be the case but who knows)
10561065

1066+
# filter those with no parent found (should actually never be the case but who knows)
1067+
nodes_with_parents = {k:v for k, v in nodes_with_parents.items() if v is not None}
1068+
1069+
# now we create a dictionary, where the key is the parent node,
1070+
# and values are its child nodes
10571071
to_merge = defaultdict(list)
10581072
for k, v in nodes_with_parents.items():
10591073
to_merge[v].append(k)
10601074

1075+
# here we get the token span, which corresponds to the list of nodes,
1076+
# where the 1st value is the parent node and all subsequent nodes
1077+
# are its children
10611078
subtree_token_spans = {}
10621079
for k, v in to_merge.items():
10631080
subtree = tuple([k] + v)
10641081
#print(meta1['alignments_dict'])
1082+
1083+
# extract the information about token spans from the metadata
10651084
span = [meta1['alignments_dict'][node] for node in subtree if meta1['alignments_dict'][node]]
1085+
1086+
# check whether the found token span is full and complete
10661087
token_span = full_span(span)
10671088
if token_span:
10681089
subtree_token_spans[subtree] = ' '.join([meta1['toks'][i] for i in token_span])
10691090
print(best_match_num_soft)
10701091
print('\nWEIGHTS DICT:\n', weight_dict, '\nALIGNMENTS:\n', best_mapping)
1092+
print('\nSUBTREE-TOKEN-SPAN:\n', subtree_token_spans)
10711093

10721094
if super_verbose:
10731095
log_helper.debug( "best match number", best_match_num_soft)

0 commit comments

Comments
 (0)