Commit ·
d1f18ad
1
Parent(s): 6d70738
fix: Handle N-to-M word replacements in analyze post-filter - Process each original word individually against corrected segment - Accept 1-to-1 small edits and 1-to-N word splits within multi-word blocks - Previously all multi-word blocks were silently rejected
Browse files755 unmodified lines756757758759760761762755 unmodified lineselse:new_words.append(current_text[start_idx:end_idx])else:new_words.extend([current_text[orig_word_positions[idx][1]:orig_word_positions[idx][2]] for idx in range(i1, i2)])elif tag == 'delete':for idx in range(i1, i2):new_words.append(current_text[orig_word_positions[idx][1]:orig_word_positions[idx][2]])755 unmodified lines756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815755 unmodified lineselse:new_words.append(current_text[start_idx:end_idx])else:# N→M replacement: process each original word individually# Build a mapping by trying to match original words to corrected wordscorr_joined = " ".join(c_segment)ci = 0 # cursor into c_segmentfor oi in range(i1, i2):o_word = orig_word_strings[oi]o_start = orig_word_positions[oi][1]o_end = orig_word_positions[oi][2]if ci < len(c_segment):c_word = c_segment[ci]# Check if this is a 1→1 small editif _is_small_spelling_change(o_word, c_word):new_words.append(c_word)suggestions.append({'start': o_start,'end': o_end,'original': o_word,'correction': c_word,'type': 'spelling',})ci += 1# Check if this is a 1→N word splitelif len(o_word) >= 5 and ci + 1 < len(c_segment):# Try to consume multiple corrected words for this one original wordsplit_parts = [c_segment[ci]]temp_ci = ci + 1joined = c_segment[ci]while temp_ci < len(c_segment) and len(joined) < len(o_word) + 2:joined += c_segment[temp_ci]split_parts.append(c_segment[temp_ci])temp_ci += 1# Check if the joined parts roughly match the originalcorr_str = " ".join(split_parts)joined_no_space = "".join(split_parts)dist = _levenshtein(o_word, joined_no_space)if dist <= 3 and len(split_parts) > 1:new_words.append(corr_str)suggestions.append({'start': o_start,'end': o_end,'original': o_word,'correction': corr_str,'type': 'spelling',})ci = temp_cielse:new_words.append(current_text[o_start:o_end])ci += 1else:new_words.append(current_text[o_start:o_end])ci += 1else:new_words.append(current_text[o_start:o_end])elif tag == 'delete':for idx in range(i1, i2):new_words.append(current_text[orig_word_positions[idx][1]:orig_word_positions[idx][2]])
src/app.py+54-1