Skip to content

Commit

Permalink
fix: don't raise error when getting bounding box by default
Browse files Browse the repository at this point in the history
display warning log
  • Loading branch information
raphael0202 committed Apr 26, 2023
1 parent 7aa97c1 commit 9208b42
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions robotoff/prediction/ocr/dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,14 @@ def get_text(

def get_match_bounding_box(
content: Union[OCRResult, str], start_idx: int, end_idx: int
):
) -> Optional[tuple[int, int, int, int]]:
"""Return a bounding box that include all words that span from
`start_idx` to `end_idx` if `content` is an OCRResult and None otherwise.
"""
if isinstance(content, str):
return None

return content.get_match_bounding_box(start_idx, end_idx)
return content.get_match_bounding_box(start_idx, end_idx, raises=False)


class OCRFullTextAnnotation:
Expand Down Expand Up @@ -383,11 +383,16 @@ def get_words_from_indices(
if not partial_match:
break

if partial_match and raises:
raise RuntimeError(
"partial match detected: reached end of text before reaching end offset %d",
end_idx,
if partial_match:
error_text = (
"partial match detected: reached end of text before reaching "
"end offset (text: %s, start_idx: %d, end_idx: %d)"
)
error_args = (self.text, start_idx, end_idx)
if raises:
raise RuntimeError(error_text % error_args)
else:
logger.warning(error_text, *error_args)

return selected

Expand Down

0 comments on commit 9208b42

Please sign in to comment.