refactor: use match_taxonomized_value utility and add CONTRIBUTING.md#1834
refactor: use match_taxonomized_value utility and add CONTRIBUTING.md#1834atheendre130505 wants to merge 6 commits intoopenfoodfacts:mainfrom
Conversation
|
Hello @atheendre130505! |
05347e2 to
6303593
Compare
|
implemented tests/unit/prediction/ocr/test_category.py with test_category_taxonomisation. |
|
hi @teolemon @raphael0202 , |
| # Contributing to Robotoff | ||
|
|
||
| Thank you for your interest in contributing to Robotoff! | ||
|
|
||
| For detailed instructions on how to contribute, please visit our [Contributing Guide](https://openfoodfacts.github.io/robotoff/introduction/contributing/). | ||
|
|
||
| You can also find more information about the project in our [documentation](https://openfoodfacts.github.io/robotoff). |
There was a problem hiding this comment.
Please leave this outside the PR, as we try to keep PRs atomic.
| def test_category_taxonomisation(mocker): | ||
| from robotoff.prediction.ocr.category import category_taxonomisation | ||
|
|
||
| # Mock match_taxonomized_value | ||
| mock_match = mocker.patch("robotoff.prediction.ocr.category.match_taxonomized_value") | ||
| mock_match.return_value = "en:mocked-category" | ||
|
|
||
| # Mock simple regex match object | ||
| mock_re_match = mocker.Mock() | ||
| mock_re_match.group.return_value = " Some Category " | ||
|
|
||
| # Test execution | ||
| result = category_taxonomisation("en:", mock_re_match) | ||
|
|
||
| # Verify normalization and args | ||
| # Expected: "en:" + normalize_tag(" Some Category ") -> "en:some-category" | ||
| mock_match.assert_called_once_with("en:some-category", "category") | ||
| assert result == "en:mocked-category" |
There was a problem hiding this comment.
I think we should use a real taxonomy to test this function. We can load taxonomies offline, there are some examples of this in the repo (using the offline parameter of the get_taxonomy function).
What:
Refactored category_taxonomisation in robotoff/prediction/ocr/category.py to use the match_taxonomized_value utility function.
Resolved an internal TODO regarding synonym matching for categories.
Added a missing CONTRIBUTING.md file to the root directory to guide new contributors.
Screenshot
N/A (Backend refactor and documentation)
Fixes bug(s)
#1833