1
2
3
4
5
6
7
8 from nltk_lite.contrib.classifier import attribute as a
9 from nltk_lite.contrib.classifier_tests import *
10 import math
11
14 attr = a.Attribute('foo', ['a','b','c'], 0)
15 self.assertEqual('foo', attr.name)
16 self.assertEqual(['a', 'b', 'c'], attr.values)
17
22
24 attr = a.Attribute('foo', ['a','b','c'], 0)
25 same = a.Attribute('foo', ['a','b','c'], 0)
26 othername = a.Attribute('foobar', ['a','b','c'], 1)
27 otherval = a.Attribute('foo',['a','b','c','d'], 0)
28 self.assertEqual(attr, same, 'they should be equal')
29 self.assertNotEqual(attr, othername, 'they are not equal')
30 self.assertNotEqual(attr, otherval, 'they are not equal')
31
40
42 attr = a.Attribute('foo', ['a','b','c'], 0)
43 expected = -(1.0/3 * math.log(1.0/3, 2)) * 3
44 self.assertAlmostEqual(expected, attr.split_info(), 6)
45
47 attr = a.Attribute('foo', ['a','b','c'], 0)
48 higher_arity = a.Attribute('foo', ['a','b','c', 'd', 'e', 'f', 'g', 'h'], 0)
49 self.assertTrue(higher_arity.split_info() > attr.split_info())
50