Skip to content

Instantly share code, notes, and snippets.

@sampottinger
Created December 3, 2013 21:18
Show Gist options
  • Save sampottinger/7777669 to your computer and use it in GitHub Desktop.
Save sampottinger/7777669 to your computer and use it in GitHub Desktop.
Updates pairs ambiguous words in the daxlab database to versions with clarification.
SELECT_TEMPALTE = 'SELECT rowid, snapshot_id, word FROM snapshot_content WHERE word="%s" ORDER BY rowid ASC'
UPDATE_TEMPLATE = 'UPDATE snapshot_content SET word="%s" WHERE rowid=%d'
def exchange_word(cursor, source_word, replace_first_word, replace_second_word):
select_operation = SELECT_TEMPLATE % source_word
results = list(cursor.execute(select_operation))
change_to_first_word_row_ids = results[::2].map(lambda x: x[0])
change_to_second_word_row_ids = results[1::2].map(lambda x: x[0])
for row_id in change_to_first_word_row_ids:
update_operation = UPDATE_TEMPLATE % (replace_first_word, row_id)
cursor.execute(update_operation)
for row_id in change_to_second_word_row_ids:
update_operation = UPDATE_TEMPLATE % (replace_second_word, row_id)
cursor.execute(update_operation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment