import networkx as nx


class ConnectedComponents:
    """This is a class for connected component detection method to cluster event logs [1]_.

    References
    ----------
    .. [1] H. Studiawan, B. A. Pratomo, and R. Anggoro, Connected component detection for authentication log
           clustering, in Proceedings of the International Seminar on Science and Technology, 2016, pp. 495-496.
    """
    def __init__(self, g):
        """This is a constructor for ConnectedComponent class

        Parameters
        ----------
        g : graph
            a graph to be clustered
        """
        self.g = g

    def get_clusters(self):
        """This method find any connected component in a graph.

        A component represents a cluster and each component will be given a cluster identifier.

        Returns
        -------
        clusters : list[list]
            List of cluster list, where each list contains index (line number) of event log.
        """
        clusters = []
        for components in nx.connected_components(self.g):
            clusters.append(components)

        cluster_id = 0
        for cluster in clusters:
            for node in cluster:
                self.g.node[node]['cluster'] = cluster_id
            cluster_id += 1

        return clusters

@@ -15,16 +15,58 @@
 x as nx%0A
+from ClusterUtility import ClusterUtility%0A
 %0A%0Aclass 
@@ -345,29 +345,15 @@
 ng, 
-in Proceedings of the
+The 2nd
  Int
@@ -449,16 +449,20 @@
 (self, g
+raph
 ):%0A     
@@ -517,16 +517,17 @@
 nt class
+.
 %0A%0A      
@@ -567,16 +567,20 @@
        g
+raph
  : graph
@@ -592,17 +592,17 @@
         
-a
+A
  graph t
@@ -615,16 +615,17 @@
 lustered
+.
 %0A       
@@ -647,12 +647,20 @@
 lf.g
- = g
+raph = graph
 %0A%0A  
@@ -845,16 +845,113 @@
 ntifier.
+%0A        This method heavily rely on the cosine similarity threshold to build an edge in a graph.
 %0A%0A      
@@ -995,19 +995,19 @@
 sters : 
-lis
+dic
 t%5Blist%5D%0A
@@ -1022,12 +1022,18 @@
     
-List
+Dictionary
  of 
@@ -1140,10 +1140,33 @@
 s = 
-%5B%5D
+%7B%7D%0A        cluster_id = 0
 %0A   
@@ -1218,16 +1218,20 @@
 s(self.g
+raph
 ):%0A     
@@ -1249,16 +1249,23 @@
 ters
-.append(
+%5Bcluster_id%5D = 
 comp
@@ -1274,19 +1274,19 @@
 ents
-)%0A%0A
+%0A  
         
 clus
@@ -1273,32 +1273,34 @@
 nents%0A          
+  
 cluster_id = 0%0A 
@@ -1286,35 +1286,37 @@
      cluster_id 
++
 = 
-0
+1%0A
 %0A        for clu
@@ -1312,151 +1312,59 @@
     
-for c
+C
 luster
- in clusters:%0A            for node in cluster:%0A                self.g.node%5Bnode%5D%5B'cluster'%5D = cluster_id%0A            cluster_id += 1
+Utility.set_cluster_id(self.graph, clusters)
 %0A%0A  

Change cluster data structure from list to dict