Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding confidence to write_function #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions csvdedupe/csvhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ def writeResults(clustered_dupes, input_file, output_file):

cluster_membership = {}
for cluster_id, (cluster, score) in enumerate(clustered_dupes):
for record_id in cluster:
cluster_membership[record_id] = cluster_id
for record_index, record_id in enumerate(cluster):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we do this as

for record_id, score in zip(cluster, score)

?

cluster_membership[record_id] = {
'cluster_id': cluster_id,
'score': score[record_index],
}

unique_record_id = cluster_id + 1

Expand All @@ -73,15 +76,19 @@ def writeResults(clustered_dupes, input_file, output_file):

heading_row = reader.next()
heading_row.insert(0, 'Cluster ID')
heading_row.insert(1, 'Confidence')
writer.writerow(heading_row)

for row_id, row in enumerate(reader):
if row_id in cluster_membership:
cluster_id = cluster_membership[row_id]
cluster_id = cluster_membership[row_id]['cluster_id']
score = cluster_membership[row_id]['score']
else:
cluster_id = unique_record_id
unique_record_id += 1
score = ''
row.insert(0, cluster_id)
row.insert(1, score)
writer.writerow(row)


Expand Down