fixed off by 1 error in replace_most_similar_chunk()

This commit is contained in:
Paul Gauthier 2023-05-10 16:22:08 -07:00
parent 9ad44d5d7a
commit 923e42c176

View file

@ -3,7 +3,7 @@ import math
from difflib import SequenceMatcher from difflib import SequenceMatcher
from pathlib import Path from pathlib import Path
# from dump import dump # from aider.dump import dump
def replace_most_similar_chunk(whole, part, replace): def replace_most_similar_chunk(whole, part, replace):
@ -22,7 +22,7 @@ def replace_most_similar_chunk(whole, part, replace):
for length in range(min_len, max_len): for length in range(min_len, max_len):
for i in range(len(whole_lines) - length + 1): for i in range(len(whole_lines) - length + 1):
chunk = whole_lines[i : i + length + 1] chunk = whole_lines[i : i + length]
chunk = "\n".join(chunk) chunk = "\n".join(chunk)
similarity = SequenceMatcher(None, chunk, part).ratio() similarity = SequenceMatcher(None, chunk, part).ratio()
@ -30,7 +30,7 @@ def replace_most_similar_chunk(whole, part, replace):
if similarity > max_similarity and similarity: if similarity > max_similarity and similarity:
max_similarity = similarity max_similarity = similarity
most_similar_chunk_start = i most_similar_chunk_start = i
most_similar_chunk_end = i + length + 1 most_similar_chunk_end = i + length
if max_similarity < similarity_thresh: if max_similarity < similarity_thresh:
return return
@ -42,6 +42,7 @@ def replace_most_similar_chunk(whole, part, replace):
+ whole_lines[most_similar_chunk_end:] + whole_lines[most_similar_chunk_end:]
) )
modified_whole = "\n".join(modified_whole) + "\n" modified_whole = "\n".join(modified_whole) + "\n"
return modified_whole return modified_whole