<commit_before>import networkx as nx
from ClusterUtility import ClusterUtility


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

    References
    ----------
    .. [Studiawan2016a] <NAME>, <NAME>, and <NAME>, Connected component detection for authentication log
                        clustering, The 2nd International Seminar on Science and Technology, 2016, pp. 495-496.
    """
    def __init__(self, graph):
        """This is a constructor for ConnectedComponent class.

        Parameters
        ----------
        graph : graph
            A graph to be clustered.
        """
        self.graph = graph

    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.
        This method heavily rely on the cosine similarity threshold to build an edge in a graph.

        Returns
        -------
        clusters : dict[list]
            Dictionary of cluster list, where each list contains index (line number) of event log.
        """
        clusters = {}
        cluster_id = 0
        for components in nx.connected_components(self.graph):
            clusters[cluster_id] = components
            cluster_id += 1

        ClusterUtility.set_cluster_id(self.graph, clusters)<commit_msg>Tidy up the docstring<commit_after>import networkx as nx
from ClusterUtility import ClusterUtility


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

    References
    ----------
    .. [Studiawan2016a] <NAME>, <NAME>, and <NAME>, Connected component detection for
                        authentication log clustering, The 2nd International Seminar on Science and Technology,
                        pp. 495-496, 2016.
    """
    def __init__(self, graph):
        """This is a constructor for ConnectedComponent class.

        Parameters
        ----------
        graph : graph
            A graph to be clustered.
        """
        self.graph = graph

    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.
        This method heavily rely on the cosine similarity threshold to build an edge in a graph.

        Returns
        -------
        clusters : dict[list]
            Dictionary of cluster list, where each list contains index (line number) of event log.
        """
        clusters = {}
        cluster_id = 0
        for components in nx.connected_components(self.graph):
            clusters[cluster_id] = components
            cluster_id += 1

        ClusterUtility.set_cluster_id(self.graph, clusters)
{'fraction_non_alphanumeric': 0.07826694619147449, 'fraction_numerical': 0.014675052410901468, 'mean_word_length': 2.146153846153846, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2754951', 'n_tokens_mistral': 723, 'n_tokens_neox': 664, 'n_words': 280}