def test_import_and_export(self):
     g = DGraph.read_dot(join(project_root(), "./dot/example.dot"))
     self.assertIsNotNone(g, "import of example.dot failed")
     g.write_dot(join(project_root(), "./tests/dot_export/example.dot"))
     g2 = DGraph.read_dot(
         join(project_root(), "./tests/dot_export/example.dot"))
     self.assertIsNotNone(g2, "import of exported example.dot failed")
     self.assertEqual(len(g2.nodes()), 24,
                      "wrong number of nodes after export")
     assert nx.algorithms.is_isomorphic(g.dgraph, g2.dgraph)
    def test_nodes(self):
        g = DGraph()
        g.add_node('1', label='kekek')
        g.add_node('2')
        g.add_node('3')
        g.add_node('4')

        self.assertEqual(len(g.nodes()), 4, "wrong number of nodes ")
        self.assertEqual(set(g.nodes()), {'1', '2', '3', '4'},
                         "wrong set of nodes")
Exemple #3
0
 def test_labeling(self):
     g = DGraph.read_dot(join(project_root(),
                              "dot/java.util.Formatter.dot"))
     den = partition.partition(g, SpectralCluster.SpectralCluster(),
                               stop_criteria.SizeCriteria(4))
     labeler = RandomWalkLabeler.RandomWalkLabeler(g, den, 'Both')
     labeler.label()
 def test_import_zip(self):
     g = DGraph.read_dot(join(project_root(), "./dot/zip.dot"))
     self.assertIsNotNone(g.dgraph, "import of zip.dot failed")
     self.assertEqual(len(g.nodes()), 5,
                      "wrong number of nodes after import")
     self.assertEqual(len(g.edges()), 9,
                      "wrong number of edges after import")
 def test_minimum_cut(self):
     print("Testing MinimumCut")
     g2 = DGraph.read_dot(join(project_root(), "dot/g2.dot"))
     algo_result = minimum_cut.MinimumCut().cluster(g2)
     self.assertIsClusterRepresentation(
         algo_result,
         "MinimumCut result is not a lists of clusters when testing g2.dot")
Exemple #6
0
    def test_labeling(self):

        g = DGraph.read_dot(join(project_root(), "dot/large/ktails4.dot"))
        den = partition.partition(g, SpectralCluster.SpectralCluster(),
                                  stop_criteria.SizeCriteria(4))
        labeler = PathLabeler.PathLabeler(g, den, labeling_on_type.EDGES)
        labeler.label()
 def test_kerningham_lin(self):
     g = DGraph.read_dot(
         os.path.join(project_root(), "dot/cvs.net.mutated.dot"))
     KL = KernighanLinCluster()
     dendrogram = partition(g,
                            clustering_algo=KL,
                            stop_criterion=SizeCriteria(3))
     print("foo")
 def test_branch_and_bound(self):
     print("Testing Branch and Bound")
     g2 = DGraph.read_dot(join(project_root(), "dot/g2.dot"))
     algo_result = BranchAndBound.BranchAndBoundCluster().cluster(g2)
     self.assertIsClusterRepresentation(
         algo_result,
         "BnB result is not a lists of clusters when testing g2.dot")
     expected = clusters_to_set([['1', '2', '3', '4'], ['5', '6', '7']])
     assert clusters_to_set(
         algo_result) == expected, "BnB did not work as expected on g2.dot"
Exemple #9
0
def test_partition():
    den = None
    g = DGraph.read_dot(os.path.join(project_root(), "dot/weighted_g2.dot"))
    print("testing partition on g2.dot for threshold=4:")
    den = partition(g, SpectralCluster.SpectralCluster(), SizeCriteria(4))
    assert len(den.node_list) == 10

    print("testing partition on g2.dot for threshold=2:")
    den = partition(g, SpectralCluster.SpectralCluster(), SizeCriteria(2))
    print('expected:', len(den.node_list))
    assert len(den.node_list) == 13
 def test_Kmeans(self):
     print("Testing Kmeans")
     g2 = DGraph.read_dot(join(project_root(), "dot/g2.dot"))
     algo_result = KMeans.KMeansClustering().cluster(g2)
     self.assertIsClusterRepresentation(
         algo_result,
         "Kmeans result is not a lists of clusters when testing g2.dot")
     expected = clusters_to_set([['1', '2', '3', '4'], ['5', '6', '7']])
     assert clusters_to_set(
         algo_result
     ) == expected, "Kmeans did not work as expected on g2.dot"
 def test_spectral(self):
     print("Testing Spectral Clustering")
     g2 = DGraph.read_dot(join(project_root(), "dot/g2.dot"))
     algo_result = SpectralCluster.SpectralCluster().cluster(g2)
     self.assertIsClusterRepresentation(
         algo_result,
         "SpectralCluster result is not a lists of clusters when testing g2.dot"
     )
     expected = clusters_to_set([['1', '2', '3'], ['4', '5', '6', '7']])
     assert clusters_to_set(
         algo_result
     ) == expected, "SpectralCluster did not work as expected on g2.dot"
 def test_labeling(self):
     g = DGraph.read_dot(os.path.join(project_root(), "dot/ssh.net.dot"))
     den = partition.partition(g, SpectralCluster.SpectralCluster(), stop_criteria.SizeCriteria(4))
     labeler = TfIdfLabeler.TfIdfLabeler(g, den, 'Both')
     labeler.label()
 def test_import_example(self):
     g = DGraph.read_dot(join(project_root(), "./dot/example.dot"))
     self.assertIsNotNone(g.dgraph, "import of example.dot failed")
     self.assertEqual(len(g.nodes()), 24,
                      "wrong number of nodes after import")
 def test_builtgraph_export(self):
     g = DGraph()
     g.add_node('1', label='kekek')
     g.add_node('2')
     g.add_node('3')
     g.add_node('4')
     g.add_edge('1', '2', weight=2)
     g.add_edge('3', '2', weight=2)
     g.write_dot(join(project_root(), "./tests/dot_export/g.dot"))
     g2 = DGraph.read_dot(join(project_root(), "./tests/dot_export/g.dot"))
     assert g2.dgraph is not None
     self.assertEqual(len(g.nodes()), 4,
                      "wrong number of nodes after export")
     self.assertEqual(len(g.edges()), 2,
                      "wrong number of edges after export")
     assert nx.algorithms.is_isomorphic(g.dgraph, g2.dgraph)
 def test_init(self):
     self.assertIsNotNone(DGraph().dgraph, "DGraph init failed")
 def test_edges(self):
     g = DGraph()
     g.add_node('1', label='kekek')
     g.add_node('2')
     g.add_node('3')
     g.add_node('4')
     g.add_edge('1', '2', weight=2)
     g.add_edge('3', '2', weight=2)
     self.assertEqual(len(g.edges()), 2, "wrong number of edges ")
Exemple #17
0
 def open(self, model_id):
     model_path = os.path.join(self.base_dir,
                               _model_name_to_filename(model_id))
     return DGraph.read_dot(model_path)