mmlearn.datasets.core.modalities.ModalityRegistry

class ModalityRegistry[source]

Bases: object

Modality registry.

A singleton class that manages the supported modalities (and their properties) in the library. The class provides methods to add new modalities and properties, and to access the existing modalities. The class is implemented as a singleton to ensure that there is only one instance of the registry in the library.

Methods

add_default_property(name, format_string)[source]

Add a new property that is applicable to all modalities.

Parameters:
  • name (str) – The name of the property.

  • format_string (str) – The format string for the property. The format string should contain a placeholder that will be replaced with the name of the modality when the property is accessed.

Warns:

UserWarning – If the property already exists for the default properties. It will overwrite the existing property.

Raises:

ValueError – If the format string is invalid. A valid format string contains at least one placeholder enclosed in curly braces.

Return type:

None

get_modality(name)[source]

Get the modality name from the registry.

Parameters:

name (str) – The name of the modality.

Returns:

The modality object from the registry.

Return type:

Modality

get_modality_properties(name)[source]

Get the properties of a modality from the registry.

Parameters:

name (str) – The name of the modality.

Returns:

The properties associated with the modality.

Return type:

dict[str, str]

has_modality(name)[source]

Check if the modality exists in the registry.

Parameters:

name (str) – The name of the modality.

Returns:

True if the modality exists in the registry, False otherwise.

Return type:

bool

list_modalities()[source]

Get the list of supported modalities in the registry.

Returns:

The list of supported modalities in the registry.

Return type:

list[Modality]

register_modality(name, modality_specific_properties=None)[source]

Add a new modality to the registry.

Parameters:
  • name (str) – The name of the modality.

  • modality_specific_properties (Optional[dict[str, str]], optional, default=None) – Additional properties specific to the modality.

Warns:

UserWarning – If the modality already exists in the registry. It will overwrite the existing modality.

Return type:

None