Exemple #1
0
    def append_extra(self, trs):
        """
        Append extra tiers in trs: Activity and PhnTokAlign.

        """
        tokenalign = trs.Find("TokensAlign")
        if tokenalign is None:
            self.print_message("No time-aligned tokens found. No extra tier can be generated.", indent=2, status=WARNING_ID)
            return trs

        # PhnTokAlign tier
        if self._options['phntok'] is True:
            try:
                phonalign = trs.Find("PhonAlign")
                tier = self.phntokalign_tier(phonalign,tokenalign)
                trs.Append(tier)
                trs.GetHierarchy().addLink("TimeAssociation", tokenalign, tier)
            except Exception as e:
                self.print_message("PhnTokAlign generation: %s"%str(e), indent=2, status=WARNING_ID)

        # Activity tier
        if self._options['activity'] is True or self._options['activityduration']:
            try:
                activity = Activity( trs )
                tier = activity.get_tier()
                if self._options['activity'] is True:
                    trs.Append(tier)
                    trs.GetHierarchy().addLink("TimeAlignment", tokenalign, tier)

                if self._options['activityduration'] is True:
                    dtier = tier.Copy()
                    dtier.SetName( "ActivityDuration" )
                    trs.Append(dtier)
                    for a in dtier:
                        d = a.GetLocation().GetDuration().GetValue()
                        a.GetLabel().SetValue( '%.3f' % d )

            except Exception as e:
                self.print_message("Activities generation: %s"%str(e), indent=2, status=WARNING_ID)

        return trs