SPPAS 4.20

Module sppas.src.annotations

Class sppasOverActivity

Description

SPPAS integration of the automatic overlaps estimator on intervals.

Constructor

Create a new instance.

Parameters
  • log: (sppasLog) Human-readable logs.
View Source
def __init__(self, log=None):
    """Create a new instance.

    :param log: (sppasLog) Human-readable logs.

    """
    super(sppasOverActivity, self).__init__('overlaps.json', log)
    self.__out_items = list()
    self.set_default_out_items()

Public functions

fix_options

Fix all options.

Parameters
  • options: (sppasOption)
View Source
def fix_options(self, options):
    """Fix all options.

        :param options: (sppasOption)

        """
    for opt in options:
        key = opt.get_key()
        if 'tiername' == key:
            self.set_tiername(opt.get_value())
        elif 'ignore' == key:
            self.set_out_items(opt.get_value())
        elif 'pattern' in key:
            self._options[key] = opt.get_value()
        else:
            raise AnnotationOptionError(key)
set_tiername

Fix the tiername option.

Parameters
  • tier_name: (str)
View Source
def set_tiername(self, tier_name):
    """Fix the tiername option.

        :param tier_name: (str)

        """
    self._options['tiername'] = sppasUnicode(tier_name).to_strip()
set_out_items

Fix the list of tags to be ignored from the given string.

Parameters
  • str_entry: (str) Entries separated by commas
View Source
def set_out_items(self, str_entry):
    """Fix the list of tags to be ignored from the given string.

        :param str_entry: (str) Entries separated by commas

        """
    self.__out_items = list()
    items = str_entry.split(',')
    if len(items) > 0:
        for item in items:
            item = item.strip()
            if len(item) > 0:
                self.__out_items.append(item)
set_default_out_items

Set the list of tags to be ignored.

View Source
def set_default_out_items(self):
    """Set the list of tags to be ignored."""
    self.__out_items = list()
    self.__out_items.append('dummy')
    self.__out_items.append('noise')
    self.__out_items.append('pause')
detection

Search for the overlaps of annotations.

Parameters
  • tier_spk1: (sppasTier)
  • tier_spk2: (sppasTier)
View Source
def detection(self, tier_spk1, tier_spk2):
    """Search for the overlaps of annotations.

        :param tier_spk1: (sppasTier)
        :param tier_spk2: (sppasTier)

        """
    out_tags = list()
    if tier_spk1.is_bool() and tier_spk2.is_bool():
        for item in self.__out_items:
            tag = sppasTag(item, tag_type='bool')
            out_tags.append(tag)
    elif tier_spk1.is_float() and tier_spk2.is_float():
        for item in self.__out_items:
            tag = sppasTag(item, tag_type='float')
            out_tags.append(tag)
    elif tier_spk1.is_int() and tier_spk2.is_int():
        for item in self.__out_items:
            tag = sppasTag(item, tag_type='int')
            out_tags.append(tag)
    elif tier_spk1.is_string() and tier_spk2.is_string():
        for item in self.__out_items:
            tag = sppasTag(item, tag_type='str')
            out_tags.append(tag)
    else:
        raise Exception('Two non-empty tiers of the same type were expected.')
    over = OverActivity(out_tags)
    return over.overlaps(tier_spk1, tier_spk2)
get_inputs

Return 2 tiers with name given in options.

Parameters
  • input_files: (list)
Raises

NoTierInputError

Returns
  • (sppasTier)
View Source
def get_inputs(self, input_files):
    """Return 2 tiers with name given in options.

        :param input_files: (list)
        :raise: NoTierInputError
        :return: (sppasTier)

        """
    if len(input_files) != 2:
        raise Exception('Invalid format of input files.')
    tier_src = None
    for filename in input_files[0]:
        parser = sppasTrsRW(filename)
        trs_input = parser.read()
        if tier_src is None:
            tier_src = trs_input.find(self._options['tiername'], case_sensitive=False)
    if tier_src is None:
        logging.error('A tier with name {:s} was expected but not found.'.format(self._options['tiername']))
        raise NoTierInputError
    tier_echo = None
    for filename in input_files[1]:
        parser = sppasTrsRW(filename)
        trs_input = parser.read()
        if tier_echo is None:
            tier_echo = trs_input.find(self._options['tiername'], case_sensitive=False)
    if tier_echo is None:
        logging.error('A tier with name {:s} was expected but not found.'.format(self._options['tiername']))
        raise NoTierInputError
    return (tier_src, tier_echo)
run

Run the automatic annotation process on an input.

Input files is a list with 2 files:

the activity of speaker 1 and the activity of the speaker 2.

Parameters
  • input_files: (list of str) Time-aligned items, Time-aligned items
  • output: (str) the output name
Returns
  • (sppasTranscription)
View Source
def run(self, input_files, output=None):
    """Run the automatic annotation process on an input.

        Input files is a list with 2 files:
        the activity of speaker 1 and the activity of the speaker 2.

        :param input_files: (list of str) Time-aligned items, Time-aligned items
        :param output: (str) the output name
        :returns: (sppasTranscription)

        """
    tier_spk1, tier_spk2 = self.get_inputs(input_files)
    new_tier = self.detection(tier_spk1, tier_spk2)
    trs_output = sppasTranscription(self.name)
    trs_output.set_meta('annotation_result_of', input_files[0][0])
    trs_output.append(new_tier)
    if output is not None:
        if len(trs_output) > 0:
            output_file = self.fix_out_file_ext(output)
            parser = sppasTrsRW(output_file)
            parser.write(trs_output)
            return [output_file]
        else:
            raise EmptyOutputError
    return trs_output
get_output_pattern

Pattern this annotation uses in an output filename.

View Source
def get_output_pattern(self):
    """Pattern this annotation uses in an output filename."""
    return self._options.get('outputpattern', '-overlaps')
get_input_patterns

Pattern this annotation expects for its input filename.

View Source
def get_input_patterns(self):
    """Pattern this annotation expects for its input filename."""
    return [self._options.get('inputpattern', '-activity')]