fix: refactor merge_result_button to use keywords for result identification

This commit is contained in:
2026-07-06 22:40:47 +08:00
parent 4a59ec58bd
commit bbc0d1352d
+11 -16
View File
@@ -53,40 +53,35 @@ def _merge_boxed_result(left: BoxedResult, right: BoxedResult) -> BoxedResult:
def merge_result_button( def merge_result_button(
results: list[BoxedResult], results: list[BoxedResult],
left_func: callable, left_keyword: str,
right_func: callable, right_keyword: str,
text_func: callable merged_text: str
) -> list[BoxedResult]: ) -> list[BoxedResult]:
""" """
Args: Args:
results: results:
left_func: Function that inputs ocr_text (str) and outputs bool left_keyword:
True means mark as left text right_keyword:
right_func: merged_text:
text_func: Function that inputs left_text (str) right_text (str) and outputs text (str)
""" """
left = None left = None
right = None right = None
for result in results: for result in results:
if left_func(result.ocr_text): if left_keyword in result.ocr_text:
left = result left = result
elif right_func(result.ocr_text): elif right_keyword in result.ocr_text:
right = result right = result
text = text_func(
left.ocr_text if left is not None else '',
right.ocr_text if right is not None else ''
)
if left is not None: if left is not None:
if right is not None: if right is not None:
results.remove(right) results.remove(right)
left.box = _merge_area(left.box, right.box) left.box = _merge_area(left.box, right.box)
left.ocr_text = text left.ocr_text = merged_text
else: else:
left.ocr_text = text left.ocr_text = merged_text
else: else:
if right is not None: if right is not None:
right.ocr_text = text right.ocr_text = merged_text
else: else:
pass pass
return results return results