flake8 canonical.py
import numpy
from affinegap import normalizedAffineGapDistance as comparator
+
def getCentroid(attribute_variants, comparator):
"""
Takes in a list of attribute values for a field,
@@ -21,7 +22,8 @@ def getCentroid(attribute_variants, comparator):
average_distance = distance_matrix.mean(0)
# there can be ties for minimum, average distance string
- min_dist_indices = numpy.where(average_distance==average_distance.min())[0]
+ min_dist_indices = numpy.where(
+ average_distance == average_distance.min())[0]
if len(min_dist_indices) > 1:
centroid = breakCentroidTie(attribute_variants, min_dist_indices)
@@ -31,28 +33,34 @@ def getCentroid(attribute_variants, comparator):
return centroid
+
def breakCentroidTie(attribute_variants, min_dist_indices):
"""
Finds centroid when there are multiple values w/ min avg distance
- (e.g. any dupe cluster of 2) right now this selects the first among a set of
- ties, but can be modified to break ties in strings by selecting the longest string
+ (e.g. any dupe cluster of 2) right now this selects the first
+ among a set of ties, but can be modified to break ties in strings
+ by selecting the longest string
+
"""
return attribute_variants[min_dist_indices[0]]
+
def getCanonicalRep(record_cluster):
"""
- Given a list of records within a duplicate cluster, constructs a canonical representation
- of the cluster by finding canonical values for each field
+ Given a list of records within a duplicate cluster, constructs a
+ canonical representation of the cluster by finding canonical
+ values for each field
+
"""
canonical_rep = {}
keys = record_cluster[0].keys()
-
- for key in record_cluster[0].keys():
+ for key in keys:
key_values = []
for record in record_cluster:
- # assume non-empty values always better than empty value for canonical record
+ # assume non-empty values always better than empty value
+ # for canonical record
if record[key]:
key_values.append(record[key])
if key_values:
