Example #1
0
    def test_TierStats(self):
        t = TierStats( self.tier )
        ds = t.ds()

        occurrences = ds.len()
        self.assertEqual(3, occurrences['toto'])
        self.assertEqual(1, occurrences['titi'])

        total = ds.total()
        self.assertEqual(5.5, total['toto'])
        self.assertEqual(1.0, total['titi'])

        mean = ds.mean()
        self.assertEqual(1.833, round(mean['toto'],3))
        self.assertEqual(1.0, mean['titi'])

        median = ds.median()
        self.assertEqual(1.5, median['toto'])
        self.assertEqual(1.0, median['titi'])

        variance = ds.variance()
        self.assertEqual(1.083, round(variance['toto'],3))

        stdev = ds.stdev()
        self.assertEqual(1.041, round(stdev['toto'],3))

        coefvariation = ds.coefvariation()
        self.assertEqual(56.773, round(coefvariation['toto'],3))
Example #2
0
    trsinput = annotationdata.io.read(trs)

    if tieridx < 0 or tieridx > trsinput.GetSize():
        print 'Error: Bad tier number.\n'
        sys.exit(1)

    tier = trsinput[tieridx]
    if tiername is None:
        tiername = tier.GetName().replace (' ','_')
    tiers.append( tier )

# ----------------------------------------------------------------------------
# Estimates stats

t = TierStats( tiers )
t.set_ngram( ngram )

ds = t.ds()
title = [ "filename", "tier", "annotation label" ]
stats = {} # used just to get the list of keys
if 0 in mode or 1 in mode:
    occurrences = ds.len()
    title.append('occurrences')
    stats = occurrences
if 0 in mode or 2 in mode:
    total = ds.total()
    title.append('total duration')
    if not stats: stats = total
if 0 in mode or 3 in mode:
    mean = ds.mean()