Use a custom on_exit function with ner.match

I want to perform an on_exit function while using the built in ner.match recipe. I have gone through the provided documents and i cannot seem to figure out how to add the on_exit function to the ner.match recipe

My code rn looks something like this

import prodigy
from prodigy.recipes.ner import match


@prodigy.recipe('custom.ner.match',
    dataset=prodigy.recipe_args['dataset'],
    spacy_model=prodigy.recipe_args['spacy_model'],
    source=prodigy.recipe_args['source'],
    patterns=prodigy.recipe_args['patterns'])
def custom_ner_match(dataset, spacy_model, source, patterns):
    """Custom wrapper for ner.teach recipe that replaces the stream."""
    
    components = match(dataset=dataset, spacy_model=spacy_model,
                    source=source, patterns=patterns)
    return components

def on_exit(controller):
    """DO SOMETHING"""
    return(0)

Thanks!

Hi! You're almost there :slightly_smiling_face: But to make the on_exit function available to your recipe and Prodigy, you actually need to return it as part of the components returned by the recipe.

In your code, components is the dict that's typically returned by recipes – e.g. {"dataset": dataset, "stream": stream} and so on. So before you return components, you need to add the on_exit:

components["on_exit"] = on_exit