Exemple #1
0
    def _create_text_content(self, tiers):
        """
        Add the content of the tier in the RichTextCtrl.
        """
        if not tiers:
            self.text_ctrl.WriteText( "Nothing to view!" )
            return

        self.text_ctrl.WriteText( "Cohen's Kappa on labels of tiers:\n" )
        tier = []
        for filename,tiers in tiers.items():
            for t in tiers:
                tier.append(t)
        self.text_ctrl.WriteText( "\n" )

        if len(tier) != 2:
            self.text_ctrl.WriteText( "Cohen's Kappa can be estimated only with exactly 2 tiers. Got %d\n"%len(tier) )
            return
        if tier[0].GetSize() != tier[1].GetSize():
            self.text_ctrl.WriteText( "Cohen's Kappa on labels of tiers can be estimated only if the 2 tiers have the same number of annotations. Got %d and %d\n"%(len(tier[0]),len(tier[1])) )
            return

        # Create the list of items in both tiers 1 and 2
        d1 = TierConverter( tier[0] )
        items1 = d1.tier_to_items( )
        d2 = TierConverter( tier[1] )
        items2 = d2.tier_to_items( )
        items = sorted(list(set(items1+items2)))

        p = d1.labels_to_vector( items )
        q = d2.labels_to_vector( items )

        kappa = Kappa(p,q)
        v = kappa.evaluate()
        self.text_ctrl.WriteText( "value = "+str(v)+"\n" )
Exemple #2
0
    def testBoundValue(self):
        d = TierConverter( self.tier )
        p,q = d.bounds_to_vector( self.tier )
        print "\n Vector p:",p
        print "\n Vector q:",q

        k = Kappa(p,q)
        self.assertTrue(k.check_vector(p))
        self.assertTrue(k.check_vector(q))
        self.assertTrue(k.check()) # check both p and q
        self.assertEqual(k.evaluate(), 1.)

        othertier = Tier()
        othertier.Append(self.x)
        othertier.Append(self.y)
        othertier.Append(self.b)
        p,q = d.bounds_to_vector( othertier )
        print "\n Vector p:",p
        print "\n Vector q:",q

        kb = Kappa(p,q)
        self.assertTrue(kb.check_vector(p))
        self.assertTrue(kb.check_vector(q))
        self.assertTrue(kb.check()) # check both p and q
        self.assertEqual(kb.evaluate(), 0.)
Exemple #3
0
    def testLabelValue(self):
        d = TierConverter( self.tier )
        items1 = d.tier_to_items( )
        items2 = d.tier_to_items( ) # ... !!! with same tier, expect kappa=1
        items = sorted(list(set(items1+items2)))

        p = d.labels_to_vector( items )
        q = d.labels_to_vector( items )

        k = Kappa(p,q)
        self.assertTrue(k.check_vector(p))
        self.assertTrue(k.check_vector(q))
        self.assertTrue(k.check()) # check both p and q
        self.assertEqual(k.evaluate(), 1.)
Exemple #4
0
 def testkappa(self):
     kappa = Kappa(self.p,self.q)
     self.assertTrue(kappa.check_vector(self.p))
     self.assertTrue(kappa.check_vector(self.q))
     self.assertTrue(kappa.check()) # check both p and q
     self.assertFalse(kappa.check_vector([ (0.,1.) , (0.,1.,0.) ]))
     self.assertFalse(kappa.check_vector([ (0.0,0.1) ]))
     v = kappa.evaluate()
     self.assertEqual(0.54545, round(v,5))
Exemple #5
0
 def testKappa3(self):
     p = [ (1.,0.,0.) , (0.,0.,1.) , (0.,1.,0.) , (1.,0.,0.) , (0.,0.,1.) ]
     q = [ (0.,0.,1.) , (0.,0.,1.) , (1.,0.,0.) , (0.,1.,0.) , (0.,0.,1.) ]
     kappa = Kappa(p,q)
     v = kappa.evaluate()
     self.assertEqual(0.0625, round(v,5))