data_juicer.utils.registry module

class data_juicer.utils.registry.Registry(name: str)[source]

Bases: object

This class is used to register some modules to registry by a repo name.

__init__(name: str)[source]

Initialization method.

Parameters:

name – a registry repo name

property name

Get name of current registry.

Returns:

name of current registry.

property modules

Get all modules in current registry.

Returns:

a dict storing modules in current registry.

list()[source]

Logging the list of module in current registry.

get(module_key)[source]

Get module named module_key from in current registry. If not found, return None.

Parameters:

module_key – specified module name

Returns:

module named module_key

register_module(module_name: str = None, module_cls: type = None, force=False)[source]

Register module class object to registry with the specified modulename.

Parameters:
  • module_name – module name

  • module_cls – module class object

  • force – Whether to override an existing class with the same name. Default: False.

Example

>>> registry = Registry()
>>> @registry.register_module()
>>> class TextFormatter:
>>>     pass
>>> class TextFormatter2:
>>>     pass
>>> registry.register_module( module_name='text_formatter2',
                            module_cls=TextFormatter2)