qXR may receive OCR text containing character substitutions, missing characters, or adjacent character swaps. Given a source string and a target string, compute the minimum cost to align the source with the target.
Allowed operations are:
Each operation has a caller-provided non-negative cost. The alignment proceeds from left to right, so a transposition consumes exactly two source and two target characters.
Implement minimum_alignment_cost(source, target, insert_cost, delete_cost, replace_cost, transpose_cost). Return an integer representing the minimum alignment cost. The inputs are strings and integer operation costs.
def minimum_alignment_cost(source, target, insert_cost, delete_cost, replace_cost, transpose_cost):