def test_three_context(self): test_string = "godspeed" test_features = set( tuple(x) for x in features.contexts(test_string, context_size=3)) expected_features = set([(('g', 'o', 'd'), 's', ('p', 'e', 'e')), (('o', 'd', 's'), 'p', ('e', 'e', 'd'))]) self.assertEqual(test_features, expected_features)
def test_one_context(self): test_string = "hello" test_features = set( tuple(x) for x in features.contexts(test_string, context_size=1)) expected_features = set([(('h', ), 'e', ('l', )), (('l', ), 'l', ('o', )), (('e', ), 'l', ('l', ))]) self.assertEqual(test_features, expected_features)
def test_one_context(self): test_string = "hello" test_features = set(tuple(x) for x in features.contexts(test_string, context_size=1)) expected_features = set([(('h',), 'e', ('l',)), (('l',), 'l', ('o',)), (('e',), 'l', ('l',))]) self.assertEqual(test_features, expected_features)
def test_three_context(self): test_string = "godspeed" test_features = set(tuple(x) for x in features.contexts(test_string, context_size=3)) expected_features = set([(('g', 'o', 'd'), 's', ('p', 'e', 'e')), (('o', 'd', 's'), 'p', ('e', 'e', 'd'))]) self.assertEqual(test_features, expected_features)
def _file_triples(self, lines): for line in lines: for triple in features.contexts(line.rstrip().split(), context_size=1): yield triple