Difference between revisions of "Artificial Intelligence/Robotoff/Adding new detections"

From Open Food Facts wiki
Jump to navigation Jump to search
Line 9: Line 9:
 
# Choose the relevant file within the insights/ocr directory (in this case: https://github.com/openfoodfacts/robotoff/blob/master/robotoff/insights/ocr/packager_code.py)
 
# Choose the relevant file within the insights/ocr directory (in this case: https://github.com/openfoodfacts/robotoff/blob/master/robotoff/insights/ocr/packager_code.py)
  
# Write the function
+
* Write the function
 
<pre>
 
<pre>
 
def process_fsc_match(match) -> str:
 
def process_fsc_match(match) -> str:
Line 16: Line 16:
 
</pre>
 
</pre>
  
# Add the function to the processing pipeline
+
* Add the function to the processing pipeline
  
 
<pre>
 
<pre>
Line 37: Line 37:
 
<pre>
 
<pre>
  
# Grab yourself a sandwich
+
* Grab yourself a sandwich
  
 
=== Plug it to Robotoff ===
 
=== Plug it to Robotoff ===

Revision as of 13:36, 3 August 2020

Finding opportunities

  1. Download the OCR JSONL
  2. grep -o '\<WORD\>' | wc -l

Using REGEXes

https://github.com/openfoodfacts/robotoff/tree/master/robotoff/insights/ocr

Add a function to add the desired match

  1. Choose the relevant file within the insights/ocr directory (in this case: https://github.com/openfoodfacts/robotoff/blob/master/robotoff/insights/ocr/packager_code.py)
  • Write the function
def process_fsc_match(match) -> str:
    fsc_code = match.group(1)
    return "FSC-{}".format(fsc_code).upper()
  • Add the function to the processing pipeline
PACKAGER_CODE: Dict[str, OCRRegex] = {
    "fr_emb": OCRRegex(
        re.compile(r"emb ?(\d ?\d ?\d ?\d ?\d) ?([a-z])?(?![a-z0-9])"),
        field=OCRField.text_annotations,
        lowercase=True,
        processing_func=process_fr_emb_match,
    ),
    "fsc": OCRRegex(
        re.compile(r"fsc.? ?(c\d{6})"),
        field=OCRField.text_annotations,
        lowercase=True,
        processing_func=process_fsc_match,
    ),
    "eu_fr": OCRRegex(
        re.compile(


* Grab yourself a sandwich

Plug it to Robotoff

Using Flashtext

https://github.com/openfoodfacts/robotoff/tree/master/data/ocr