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
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:
Create a sppasAnnSet instance.
def __init__(self):
"""Create a sppasAnnSet instance."""
super(sppasAnnSet, self).__init__()
Make a deep copy of self.
Overridden to return a sppasAnnSet() instead of a sppasBaseSet().
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
Create a tier from the data set.
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
Implements the '&' operator between 2 data sets.
Overridden to return a sppasAnnSet() instead of a sppasBaseSet().
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