SPPAS 4.22

https://sppas.org/

Module sppas.src.anndata

Class sppasAnnSet

Description

Manager for a set of annotations.

Mainly used with the data that are the result of the tier filter system. A sppasAnnSet() manages a dictionary with:

  • key: an annotation
  • value: a list of strings

Constructor

Create a sppasAnnSet instance.

View Source
def __init__(self):
    """Create a sppasAnnSet instance."""
    super(sppasAnnSet, self).__init__()

Public functions

copy

Make a deep copy of self.

Overridden to return a sppasAnnSet() instead of a sppasBaseSet().

View Source
def copy(self):
    """Make a deep copy of self.

        Overridden to return a sppasAnnSet() instead of a sppasBaseSet().

        """
    d = sppasAnnSet()
    for data, value in self._data_set.items():
        d.append(data, value)
    return d

to_tier

Create a tier from the data set.

Parameters
  • name: (str) Name of the tier to be returned
  • annot_value: (bool) format of the resulting annotation label. By default, the label of the annotation is used. Instead, its value in the data set is used.
Returns
  • (sppasTier)
View Source
def to_tier(self, name='AnnSet', annot_value=False):
    """Create a tier from the data set.

        :param name: (str) Name of the tier to be returned
        :param annot_value: (bool) format of the resulting annotation label.             By default, the label of the annotation is used. Instead,             its value in the data set is used.

        :returns: (sppasTier)

        """
    tier = sppasTier(name)
    for ann in self._data_set:
        labels = list()
        if annot_value is True:
            for value in self._data_set[ann]:
                labels.append(sppasLabel(sppasTag(value)))
        else:
            for l in ann.get_labels():
                labels.append(l.copy())
        new_ann = tier.create_annotation(ann.get_location().copy(), labels)
        for key in ann.get_meta_keys():
            if key != 'id':
                new_ann.set_meta(key, ann.get_meta(key))
    return tier

Overloads

__and__

Implements the '&' operator between 2 data sets.

Overridden to return a sppasAnnSet() instead of a sppasBaseSet().

Parameters
  • other
View Source
def __and__(self, other):
    """Implements the '&' operator between 2 data sets.

        Overridden to return a sppasAnnSet() instead of a sppasBaseSet().

        """
    d = sppasAnnSet()
    for data in self:
        if data in other:
            d.append(data, self.get_value(data))
            d.append(data, other.get_value(data))
    return d