diff --git a/robotoff/prediction/ocr/category.py b/robotoff/prediction/ocr/category.py index 89b9f761aa..06ab1be245 100644 --- a/robotoff/prediction/ocr/category.py +++ b/robotoff/prediction/ocr/category.py @@ -98,16 +98,18 @@ def find_category(content: Union[OCRResult, str]) -> List[Prediction]: for match in ocr_regex.regex.finditer(text): - category_value = ocr_regex.processing_func(lang, match) - - if category_value is not None: - - predictions.append( - Prediction( - type=PredictionType.category, - value_tag=category_value, - predictor="regex", - data={"text": match.group(), "notify": ocr_regex.notify}, - ) + if ocr_regex.processing_func: + category_value = ocr_regex.processing_func(lang, match) + + if category_value is None: + continue + + predictions.append( + Prediction( + type=PredictionType.category, + value_tag=category_value, + predictor="regex", + data={"text": match.group(), "notify": ocr_regex.notify}, ) + ) return predictions