SPPAS 4.20

Module sppas.src.structs

Class sppasMetaInfo

Description

Meta information manager.

  • author: Brigitte Bigi
  • organization: Laboratoire Parole et Langage, Aix-en-Provence, France
  • contact: contact@sppas.org
  • license: GPL, v3
  • copyright: Copyright (C) 2011-2019 Brigitte Bigi

Meta-information is a sorted collection of pairs (key, value) where

value is a tuple with first argument of type boolean to indicate the

state of the key: enabled/disabled.

Manage meta information of type (key,value). Allows to enable/disable

each one. Keys are unicode strings, and values can be of any type.

Example
>>> m = sppasMetaInfo()
>>> m.add_metainfo('author', 'Brigitte Bigi')
>>> m.add_metainfo('version', (1,8,2))

Constructor

Create a new sppasMetaInfo instance.

View Source
def __init__(self):
    """Create a new sppasMetaInfo instance.

    """
    super(sppasMetaInfo, self).__init__()
    self._metainfo = collections.OrderedDict()

Public functions

is_enable_metainfo

Return the status of a given key.

Parameters
  • key: (str) The key of the meta-information
Raises

MetaKeyError

View Source
def is_enable_metainfo(self, key):
    """Return the status of a given key.

        :param key: (str) The key of the meta-information
        :raises: MetaKeyError

        """
    if u(key) not in self._metainfo:
        raise MetaKeyError(key)
    return self._metainfo[u(key)][0]
get_metainfo

Return the value of a given key.

Parameters
  • key: (str) The key of the meta-information
Raises

MetaKeyError

View Source
def get_metainfo(self, key):
    """Return the value of a given key.

        :param key: (str) The key of the meta-information
        :raises: MetaKeyError

        """
    if u(key) not in self._metainfo:
        raise MetaKeyError(key)
    return self._metainfo[u(key)][1]
enable_metainfo

Enable/Disable a meta information.

Parameters
  • key: (str) The key of the meta-information
  • value: (bool) Status of the meta-information
Raises

MetaKeyError

View Source
def enable_metainfo(self, key, value=True):
    """Enable/Disable a meta information.

        :param key: (str) The key of the meta-information
        :param value: (bool) Status of the meta-information
        :raises: MetaKeyError

        """
    if u(key) not in self._metainfo.keys():
        raise MetaKeyError(key)
    self._metainfo[u(key)][0] = bool(value)
add_metainfo

Fix a meta information or update it.

Parameters
  • key: (str) The key of the meta-information
  • strv: (str)
View Source
def add_metainfo(self, key, strv):
    """Fix a meta information or update it.

        :param key: (str) The key of the meta-information
        :param strv: (str)

        """
    self._metainfo[u(key)] = [True, strv]
pop_metainfo

Pop a meta information.

Parameters
  • key: (str) The key of the meta-information
Raises

MetaKeyError

View Source
def pop_metainfo(self, key):
    """Pop a meta information.

        :param key: (str) The key of the meta-information
        :raises: MetaKeyError

        """
    if u(key) not in self._metainfo.keys():
        raise MetaKeyError(key)
    del self._metainfo[u(key)]
keys_enabled

Return a list of the keys of enabled meta information.

Returns
  • list of unicode strings
View Source
def keys_enabled(self):
    """Return a list of the keys of enabled meta information.

        :returns: list of unicode strings

        """
    return [key for key in self._metainfo.keys() if self._metainfo[key][0] is True]

Overloads

__len__

Return the number of meta info (enabled+disabled).

View Source
def __len__(self):
    """Return the number of meta info (enabled+disabled)."""
    return len(self._metainfo)