def test_epsilon_context_free_path_querying_matrices(self): grammar = CNF.from_file(epsilon_matrices_grammar_path) graph = Graph.from_file(graph_path) actual_res = context_free_path_querying_matrices(grammar, graph) self.assertEqual(actual_res['A'].nonzero().nvals, 3) self.assertEqual(actual_res['B'].nonzero().nvals, 2) self.assertEqual(actual_res['S'].nonzero().nvals, 5)
def test_cfpq(self): grammar = CNF.from_file(grammar_path, is_reduced=True) graph = Graph.from_file(graph_path) actual_res = context_free_path_querying(grammar, graph) self.assertEqual(len(actual_res), len(expected_res)) for tuple in expected_res: self.assertTrue(actual_res.__contains__(tuple))
def test_aNbN_cyk_reduced(self): grammar = CNF.from_file(aNbN, is_reduced=True) self.assertTrue(cyk([], grammar)) self.assertTrue(cyk([a, b], grammar)) self.assertTrue(cyk([a, a, b, b], grammar)) self.assertTrue(cyk([a, a, a, a, a, b, b, b, b, b], grammar)) self.assertFalse(cyk([a, b, a, b], grammar)) self.assertFalse(cyk([a, b, a], grammar)) self.assertFalse(cyk([a, a, a, a, b], grammar)) self.assertFalse(cyk([a, b, b, b, b], grammar)) self.assertFalse(cyk([a, a, a, a, a], grammar)) self.assertFalse(cyk([b, b, b, b, b], grammar))
def test_aNbN_cyk(self): grammar = CNF.from_file(aNbN) self.assertTrue(cyk([], grammar)) self.assertTrue(cyk([a, b], grammar)) self.assertTrue(cyk([a, a, b, b], grammar)) self.assertTrue(cyk([a, a, a, a, a, b, b, b, b, b], grammar)) self.assertFalse(cyk([a, b, a, b], grammar)) self.assertFalse(cyk([a, b, a], grammar)) self.assertFalse(cyk([a, a, a, a, b], grammar)) self.assertFalse(cyk([a, b, b, b, b], grammar)) self.assertFalse(cyk([a, a, a, a, a], grammar)) self.assertFalse(cyk([b, b, b, b, b], grammar))
def test_task_4_3_1(self): grammar = CNF.from_file(task_1_grammar, Variable('E')) self.assertFalse(cyk([], grammar)) self.assertTrue(cyk([open, n, plus, n, close, mult, n], grammar)) self.assertTrue(cyk([n, plus, n, mult, n], grammar)) self.assertTrue(cyk([n, plus, n, plus, n, plus, n], grammar)) self.assertTrue( cyk([n, plus, open, n, mult, n, close, plus, n], grammar)) self.assertFalse(cyk([n, plus, n, mult, n, close, plus, n], grammar)) self.assertFalse(cyk([n, plus, open, n, mult, n, close, n], grammar)) self.assertFalse(cyk([n, plus, open, n, mult, close, plus, n], grammar)) self.assertFalse(cyk([plus, open, n, mult, n, close, plus, n], grammar))