UDFs in Refiner

User Defined Functions (UDFs) allow the user to provide custom functionality in Refiner.

Using UDFs in a Refiner Program

See Script folders and registration functions for how to set up your Python scripts folder and register your UDFs.

To use your UDFs within a Refiner program, link your Refiner program to your scripts folder by going to File > Settings > Scripts Folder and selecting the folder using the file selector dialog.

Special input variables

UDFs in Refiner have access to the following special variables, which contain information about the document being processed and Flow runtime metadata.

  • INPUT_COL is the text of the record being processed.

  • INPUT_FILEPATH is the path on disk of the file being processed

  • INPUT_IBOCR_RECORD is the IBOCRRecord data structure. This structure has the text and coordinates with other metadata.

  • LOGGER is a Logger object

  • REFINER_FNS is an API for executing built-in Refiner functions within a UDF

  • ROOT_OUTPUT_FOLDER refers to the output folder of the Flow in progress

  • CONFIG is a set of key-value pairs that are dynamically passed at runtime into a Flow

    • An example runtime config is: py {"key1": "val1", "key2": "val2"}
Note

Flow run variables (ROOT_OUTPUT_FOLDER and CONFIG) are not available when running the function in the Refiner app.

You can access these variables in the UDF by either passing them as an input argument when invoking the UDF:

my_function(INPUT_COL)

or you can access them in your UDF via the FnContext object:

def my_function(**kwargs):
 fn_context = kwargs.get("_FN_CONTEXT_KEY")
 config, err = fn_context.get_by_col_name("CONFIG")
 if err:
    return err

See FnContext for additional functions you can access.

Importing files, Dev Exchange packages or third-party libraries

You can information in the main UDF page on how to import code from other files, use Dev Exchange packages, and see a list of the available third-party Python libraries.

Provenance tracking

Provenance tracking allows the platform to highlight where in the original document the result of a function comes from. When creating a UDF, users need to manually add provenance tracking. See Provenance Tracking for more details on how to provenance-track your UDF.