Skip to content

Registry¤

The registry component of Scrubber maintains a catalogue of registered functions that can be imported individually as needed. The registry enables the functions to be referenced by name using string values. The code registry is created and accessed using the catalogue library by Explosion.

Registered functions can be retrieved individually using lower_case = scrubber_components.get("lower_case"). Multiple functions can be loaded using the load_components function:

lexos.scrubber.registry.load_component(s) ¤

Load a single component from a string.

Parameters:

Name Type Description Default
s str

The name of the function.

required
Source code in lexos\scrubber\registry.py
46
47
48
49
50
51
52
def load_component(s: str):
    """Load a single component from a string.

    Args:
        s: The name of the function.
    """
    return scrubber_components.get(s)

lexos.scrubber.registry.load_components(t) ¤

Load components from a tuple.

Parameters:

Name Type Description Default
t tuple

A tuple containing string names of functions.

required
Source code in lexos\scrubber\registry.py
55
56
57
58
59
60
61
62
def load_components(t: tuple):
    """Load components from a tuple.

    Args:
        t: A tuple containing string names of functions.
    """
    for item in t:
        yield scrubber_components.get(item)

Note

Custom functions can be registered by first creating the function and then adding it to the registry. An example is given below:

from lexos.scrubber.registry import scrubber_components

def title_case(text):
    """Convert text to title case using `title()`"""
    return text.title()

scrubber_components.register("title_case", func=title_case)