Skip to content

Utilities

Info

For the inference of engines based on multimedia types, we use the singledispatch decorator to simplify the selection process of the appropriate engines. The decorator transforms a function into a generic function that can have different engine implementations depending on the type of the input media.

engine(media)

Engine singledispatch factory. Use the media input to infer the right engine.

Usage:

# create an image type to pass into engine function
image = harvest.image(path=Path("image.jpg"))
engine = processing.engine(image)

Parameters:

Name Type Description Default
media Media[Path]

The media type to dispatch

required

Returns:

Type Description
Engine

The appropriate engine implementation for the type of media

Raises:

Type Description
ProcessingEngineError

If any error occurs during engine initialization

Source code in nucleus/sdk/processing/process.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@functools.singledispatch
def engine(media: Media[Path]) -> Engine:
    """Engine singledispatch factory.
    Use the media input to infer the right engine.

    Usage:

        # create an image type to pass into engine function
        image = harvest.image(path=Path("image.jpg"))
        engine = processing.engine(image)

    :param media: The media type to dispatch
    :return: The appropriate engine implementation for the type of media
    :raises ProcessingEngineError:  If any error occurs during engine initialization


    """
    raise NotImplementedError(f'cannot process not registered media `{media}')