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_epsilon_cfpq_tensors(self):
     grammar, epsilon_set = Graph.recursive_automata_from_file(epsilon_tensors_grammar_path)
     graph = Graph.from_file(graph_path)
     actual_res = context_free_path_querying_tensors(grammar, epsilon_set, graph)
     self.assertEqual(actual_res['a'].nonzero().nvals, 3)
     self.assertEqual(actual_res['b'].nonzero().nvals, 2)
     self.assertEqual(actual_res['S'].nonzero().nvals, 9)
 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))
Example #4
0
 def test_from_file(self):
     graph = Graph.from_file(test_resources_path + 'graph.txt')
     self.assertEqual(graph['a'].nonzero().nvals, 1)
     self.assertEqual(graph['b'].nonzero().nvals, 2)
     self.assertEqual(graph['c'].nonzero().nvals, 2)
     self.assertTrue(graph['a'][0, 1])
     self.assertTrue(graph['b'][1, 2])
     self.assertTrue(graph['c'][2, 3])
     self.assertTrue(graph['c'][0, 1])
     self.assertTrue(graph['b'][1, 3])
 def test_graph_regex_abc(self):
     args = parser.parse_args(
         args=('--graph ' + resources_path + '/graph.txt ' + '--queries ' +
               resources_path + '/queries/regex_abc.txt').split())
     graph = Graph.from_file(args.graph)
     query = Graph.from_regex_file(args.queries)
     automata, reachable_vertices_matrix = execute_query(args, graph, query)
     excepted_reachable_vertices = {(0, 1), (0, 2), (0, 3), (1, 2), (1, 3),
                                    (2, 3)}
     for i, j, _ in zip(*reachable_vertices_matrix.nonzero().to_lists()):
         self.assertEqual(reachable_vertices_matrix[i, j], (i, j)
                          in excepted_reachable_vertices)
 def test_graph_regex_abc_from0_to2(self):
     args = parser.parse_args(
         args=('--graph ' + resources_path + '/graph.txt ' + '--queries ' +
               resources_path + '/queries/regex_abc.txt ' + '--fr ' +
               resources_path + '/vertices_0.txt ' + '--to ' +
               resources_path + '/vertices_2.txt').split())
     graph = Graph.from_file(args.graph)
     query = Graph.from_regex_file(args.queries)
     automata, reachable_vertices_matrix = execute_query(args, graph, query)
     self.assertEqual(automata['a'].nonzero().nvals, 1)
     self.assertEqual(automata['b'].nonzero().nvals, 2)
     self.assertEqual(automata['c'].nonzero().nvals, 2)
     excepted_reachable_vertices = {(0, 2)}
     for i, j, _ in zip(*reachable_vertices_matrix.nonzero().to_lists()):
         self.assertEqual(reachable_vertices_matrix[i, j], (i, j)
                          in excepted_reachable_vertices)
Example #7
0
                     type=str,
                     help='sqr closure is default, set adj for adj closure')
 parser.add_argument(
     '--fr',
     required=False,
     default=None,
     type=str,
     help='path to file with start vertices\nfile format:\n0 1 2')
 parser.add_argument(
     '--to',
     required=False,
     default=None,
     type=str,
     help='path to file with end vertices\nfile format:\n0 1 2')
 args = parser.parse_args()
 graph = Graph.from_file(args.graph)
 for subdir, dirs, files in os.walk(args.queries):
     for filename in files:
         filepath = subdir + os.sep + filename
         print(filepath)
         queryGraph = Graph.from_regex_file(filepath)
         start_working_time = time.time()
         intersection, reachable_vertices = execute_query(
             args, graph, queryGraph)
         print('intersection statistic:')
         counter = 0
         for label, matrix in intersection.label_matrices.items():
             counter += matrix.nonzero().nvals
             # print('label: ', label, ': ', matrix.nonzero().nvals, ' - vertices amount')
         print(args.graph, ': vertices amount: ', counter)
         start_printing_working_time = time.time()