def register_encoder(
    name: str) -> Callable[[Type[_BaseEncoderVar]], Type[_BaseEncoderVar]]:
  """Register encoder.

  Encoder should implement BaseEncoder abstraction. Used as decorator, for
  example:

  @register_encoder('my_encoder')
  class MyEncoder(BaseEncoder):

  Args:
    name: name of registered encoder.

  Returns:
    Mapping from BaseEncoder to BaseEncoder.
  """

  def _wrap(cls: Type[_BaseEncoderVar]) -> Type[_BaseEncoderVar]:
    """Decorator inner wrapper needed to support `name` argument."""
    if not issubclass(cls, base_encoder.BaseEncoder):
      raise TypeError(
          'Invalid encoder. Encoder %s does not subclass BaseEncoder.' %
          cls.__name__)

    if name in _ENCODER_REGISTRY:
      raise ValueError(
          'Encoder name %s has already been registered with class %s' %
          (name, _ENCODER_REGISTRY[name].__name__))

    _ENCODER_REGISTRY[name] = cls

    return cls

  return _wrap
Register encoder.

  Encoder should implement BaseEncoder abstraction. Used as decorator, for
  example:

  @register_encoder('my_encoder')
  class MyEncoder(BaseEncoder):

  Args:
    name: name of registered encoder.

  Returns:
    Mapping from BaseEncoder to BaseEncoder.
  
language/mentionmemory/encoders/encoder_registry.py