SPPAS 4.20

Module sppas.src.analysis

Class RelationFilterTier

Description

This class applies predefined filters on a tier.

Example:

Example
>>> ft = RelationFilterTier((["overlaps", "overlappedby"], [("overlap_min", 0.04)]), fit=False)
>>> res_tier = ft.filter_tier(tier_x, tier_y)

Constructor

Filter process of a tier.

"annot_format" has an impact on the labels of the ann results but

"fit" has an impact on their localizations.

Parameters
  • filters: (tuple) ([list of functions], [list of options]) each option is a tuple with (name, value)
  • annot_format: (bool) The annotation result contains the name of the filter (if True) or the original label (if False)
  • fit: (bool) The annotation result fits the other tier.
View Source
def __init__(self, filters, annot_format=False, fit=False):
    """Filter process of a tier.

    "annot_format" has an impact on the labels of the ann results but
    "fit" has an impact on their localizations.

    :param filters: (tuple) ([list of functions], [list of options])
    each option is a tuple with (name, value)
    :param annot_format: (bool) The annotation result contains the
    name of the filter (if True) or the original label (if False)
    :param fit: (bool) The annotation result fits the other tier.

    """
    self.__filters = filters
    self.__annot_format = bool(annot_format)
    self.__fit = bool(fit)

Public functions

filter_tier

Apply the filters on the given tier.

Parameters
  • tier: (sppasTier) The tier to filter annotations
  • tier_y: (sppasTier) The tier to be in relation with
  • out_tiername: (str) Name or the filtered tier
View Source
def filter_tier(self, tier, tier_y, out_tiername='Filtered'):
    """Apply the filters on the given tier.

        :param tier: (sppasTier) The tier to filter annotations
        :param tier_y: (sppasTier) The tier to be in relation with
        :param out_tiername: (str) Name or the filtered tier

        """
    logging.info('Apply sppasTiersFilter() on tier: {:s}'.format(tier.get_name()))
    sfilter = sppasTierFilters(tier)
    ann_set = sfilter.rel(tier_y, *self.__filters[0], **{self.__filters[1][i][0]: self.__filters[1][i][1] for i in range(len(self.__filters[1]))})
    ft = ann_set.to_tier(name=out_tiername, annot_value=self.__annot_format)
    if self.__fit:
        result = ft.fit(tier_y)
        result.set_name(out_tiername)
        return result
    return ft