Created
December 3, 2013 21:18
-
-
Save sampottinger/7777669 to your computer and use it in GitHub Desktop.
Updates pairs ambiguous words in the daxlab database to versions with clarification.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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