@@ -1046,28 +1046,50 @@ def main(arguments):
1046
1046
meta_available = bool (meta1 ['labels_dict' ] and meta2 ['labels_dict' ])
1047
1047
1048
1048
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
1050
1053
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
1051
1056
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
1052
1059
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
1053
1063
nodes_with_parents = {node :find_parent (labels_dict_reversed [node ])
1054
1064
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)
1056
1065
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
1057
1071
to_merge = defaultdict (list )
1058
1072
for k , v in nodes_with_parents .items ():
1059
1073
to_merge [v ].append (k )
1060
1074
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
1061
1078
subtree_token_spans = {}
1062
1079
for k , v in to_merge .items ():
1063
1080
subtree = tuple ([k ] + v )
1064
1081
#print(meta1['alignments_dict'])
1082
+
1083
+ # extract the information about token spans from the metadata
1065
1084
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
1066
1087
token_span = full_span (span )
1067
1088
if token_span :
1068
1089
subtree_token_spans [subtree ] = ' ' .join ([meta1 ['toks' ][i ] for i in token_span ])
1069
1090
print (best_match_num_soft )
1070
1091
print ('\n WEIGHTS DICT:\n ' , weight_dict , '\n ALIGNMENTS:\n ' , best_mapping )
1092
+ print ('\n SUBTREE-TOKEN-SPAN:\n ' , subtree_token_spans )
1071
1093
1072
1094
if super_verbose :
1073
1095
log_helper .debug ( "best match number" , best_match_num_soft )
0 commit comments