#NEWLINE# def _get_block_matches( self , attributes_a , attributes_b , filter_set_a = None , filter_set_b = None , delta = ( 0 , 0 , 0 ) , tiebreak_with_block_similarity = False ) : #NEWLINE# #INDENT# '\n        :param attributes_a:    A dict of blocks to their attributes\n        :param attributes_b:    A dict of blocks to their attributes\n\n        The following parameters are optional.\n\n        :param filter_set_a:    A set to limit attributes_a to the blocks in this set.\n        :param filter_set_b:    A set to limit attributes_b to the blocks in this set.\n        :param delta:           An offset to add to each vector in attributes_a.\n        :returns:               A list of tuples of matching objects.\n        ' #NEWLINE# if ( filter_set_a is None ) : #NEWLINE# #INDENT# filtered_attributes_a = { k : v for ( k , v ) in attributes_a . items ( ) } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# filtered_attributes_a = { k : v for ( k , v ) in attributes_a . items ( ) if ( k in filter_set_a ) } #NEWLINE# #UNINDENT# if ( filter_set_b is None ) : #NEWLINE# #INDENT# filtered_attributes_b = { k : v for ( k , v ) in attributes_b . items ( ) } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# filtered_attributes_b = { k : v for ( k , v ) in attributes_b . items ( ) if ( k in filter_set_b ) } #NEWLINE# #UNINDENT# for k in filtered_attributes_a : #NEWLINE# #INDENT# filtered_attributes_a [ k ] = tuple ( ( ( i + j ) for ( i , j ) in zip ( filtered_attributes_a [ k ] , delta ) ) ) #NEWLINE# #UNINDENT# for k in filtered_attributes_b : #NEWLINE# #INDENT# filtered_attributes_b [ k ] = tuple ( ( ( i + j ) for ( i , j ) in zip ( filtered_attributes_b [ k ] , delta ) ) ) #NEWLINE# #UNINDENT# closest_a = _get_closest_matches ( filtered_attributes_a , filtered_attributes_b ) #NEWLINE# closest_b = _get_closest_matches ( filtered_attributes_b , filtered_attributes_a ) #NEWLINE# if tiebreak_with_block_similarity : #NEWLINE# #INDENT# for a in closest_a : #NEWLINE# #INDENT# if ( len ( closest_a [ a ] ) > 1 ) : #NEWLINE# #INDENT# best_similarity = 0 #NEWLINE# best = [ ] #NEWLINE# for x in closest_a [ closest_b ] : #NEWLINE# #INDENT# similarity = self . block_similarity ( a , x ) #NEWLINE# if ( similarity > best_similarity ) : #NEWLINE# #INDENT# best_similarity = similarity #NEWLINE# best = [ x ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( similarity == best_similarity ) : #NEWLINE# #INDENT# best . append ( x ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# closest_a [ a ] = best #NEWLINE# #UNINDENT# #UNINDENT# for b in closest_b : #NEWLINE# #INDENT# if ( len ( closest_b [ b ] ) > 1 ) : #NEWLINE# #INDENT# best_similarity = 0 #NEWLINE# best = [ ] #NEWLINE# for x in closest_b [ b ] : #NEWLINE# #INDENT# similarity = self . block_similarity ( x , b ) #NEWLINE# if ( similarity > best_similarity ) : #NEWLINE# #INDENT# best_similarity = similarity #NEWLINE# best = [ x ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( similarity == best_similarity ) : #NEWLINE# #INDENT# best . append ( x ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# closest_b [ b ] = best #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# matches = [ ] #NEWLINE# for a in closest_a : #NEWLINE# #INDENT# if ( len ( closest_a [ a ] ) == 1 ) : #NEWLINE# #INDENT# match = closest_a [ a ] [ 0 ] #NEWLINE# if ( ( len ( closest_b [ match ] ) == 1 ) and ( closest_b [ match ] [ 0 ] == a ) ) : #NEWLINE# #INDENT# matches . append ( ( a , match ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return matches