# Path: skmultilearn/cluster/base.py
# class LabelGraphClustererBase(object):
#     """An abstract base class for Label Graph clustering
# 
#     Inherit it in your classifier according to`developer guide <../developer.ipynb>`_.
# 
#     """
# 
#     def __init__(self, graph_builder):
#         """
# 
#         Attributes
#         ----------
#         graph_builder : a  GraphBuilderBase derivative class
#             a graph building class for the clusterer
#         """
#         super(LabelGraphClustererBase, self).__init__()
#         self.graph_builder = graph_builder
# 
#     def fit_predict(self, X, y):
#         """ Abstract method for clustering label space
# 
#         Implement it in your classifier according to`developer guide <../developer.ipynb>`_.
# 
#         Raises
#         ------
#         NotImplementedError
#             this is an abstract method
#         """
#         raise NotImplementedError("LabelGraphClustererBase::fit_predict()")
# 
# Path: skmultilearn/cluster/helpers.py
# def _membership_to_list_of_communities(membership_vector, size):
#     """Convert membership vector to list of lists of vertices in each community
# 
#     Parameters
#     ----------
#     membership_vector : list of int
#         community membership i.e. vertex/label `i` is in community `membership_vector[i]`
#     size : int
#         the number of communities present in the membership vector
# 
# 
#     Returns
#     -------
#     list_of_members : list of lists of int
#         list of lists of vertex/label ids in each community per community
#     """
#     list_of_members = [[] for _ in range(size)]
#     for vertex_id, community_id in enumerate(membership_vector):
#         list_of_members[community_id].append(vertex_id)
#     return list_of_members
# 
# def _overlapping_membership_to_list_of_communities(membership_vector, size):
#     """Convert membership vector to list of lists of vertices/labels in each community
# 
#     Parameters
#     ----------
#     membership_vector : list of lists of int
#         community membership i.e. vertex/label `i` is in communities
#         from list `membership_vector[i]`
#     size : int
#         the number of communities present in the membership vector
# 
# 
#     Returns
#     -------
#     list_of_members : list of lists of int
#         list of lists of vertex/label ids in each community per community
#     """
#     list_of_members = [[] for _ in range(size)]
#     for vertex_id, community_ids in enumerate(membership_vector):
#         for community_id in community_ids:
#             list_of_members[community_id].append(vertex_id)
#     return list_of_members


import graph_tool.all as gt
import numpy as np
from .base import LabelGraphClustererBase
from .helpers import _membership_to_list_of_communities, _overlapping_membership_to_list_of_communities
                deg_corr=self.use_degree_correlation,
                overlap=self.allow_overlap,
                state_args=dict(recs=[weights],
                                rec_types=[self.weight_model])
            )
        else:
            self.model_ = self._model_fit_function()(
                graph,
                deg_corr=self.use_degree_correlation,
                overlap=self.allow_overlap
            )
        return self._detect_communities()

    def _detect_communities(self):
        if self.nested:
            lowest_level = self.model_.get_levels()[0]
        else:
            lowest_level = self.model_

        number_of_communities = lowest_level.get_B()
        if self.allow_overlap:
            # the overlaps block returns
            # membership vector, and also edges vectors, we need just the membership here at the moment
            membership_vector = list(lowest_level.get_overlap_blocks()[0])
        else:
            membership_vector = list(lowest_level.get_blocks())

        if self.allow_overlap:
            return _overlapping_membership_to_list_of_communities(membership_vector, number_of_communities)


# Path: skmultilearn/cluster/base.py
# class LabelGraphClustererBase(object):
#     """An abstract base class for Label Graph clustering
# 
#     Inherit it in your classifier according to`developer guide <../developer.ipynb>`_.
# 
#     """
# 
#     def __init__(self, graph_builder):
#         """
# 
#         Attributes
#         ----------
#         graph_builder : a  GraphBuilderBase derivative class
#             a graph building class for the clusterer
#         """
#         super(LabelGraphClustererBase, self).__init__()
#         self.graph_builder = graph_builder
# 
#     def fit_predict(self, X, y):
#         """ Abstract method for clustering label space
# 
#         Implement it in your classifier according to`developer guide <../developer.ipynb>`_.
# 
#         Raises
#         ------
#         NotImplementedError
#             this is an abstract method
#         """
#         raise NotImplementedError("LabelGraphClustererBase::fit_predict()")
# 
# Path: skmultilearn/cluster/helpers.py
# def _membership_to_list_of_communities(membership_vector, size):
#     """Convert membership vector to list of lists of vertices in each community
# 
#     Parameters
#     ----------
#     membership_vector : list of int
#         community membership i.e. vertex/label `i` is in community `membership_vector[i]`
#     size : int
#         the number of communities present in the membership vector
# 
# 
#     Returns
#     -------
#     list_of_members : list of lists of int
#         list of lists of vertex/label ids in each community per community
#     """
#     list_of_members = [[] for _ in range(size)]
#     for vertex_id, community_id in enumerate(membership_vector):
#         list_of_members[community_id].append(vertex_id)
#     return list_of_members
# 
# def _overlapping_membership_to_list_of_communities(membership_vector, size):
#     """Convert membership vector to list of lists of vertices/labels in each community
# 
#     Parameters
#     ----------
#     membership_vector : list of lists of int
#         community membership i.e. vertex/label `i` is in communities
#         from list `membership_vector[i]`
#     size : int
#         the number of communities present in the membership vector
# 
# 
#     Returns
#     -------
#     list_of_members : list of lists of int
#         list of lists of vertex/label ids in each community per community
#     """
#     list_of_members = [[] for _ in range(size)]
#     for vertex_id, community_ids in enumerate(membership_vector):
#         for community_id in community_ids:
#             list_of_members[community_id].append(vertex_id)
#     return list_of_members


# Path: skmultilearn/cluster/graphtool.py
import graph_tool.all as gt
import numpy as np
from .base import LabelGraphClustererBase
from .helpers import _membership_to_list_of_communities, _overlapping_membership_to_list_of_communities

                deg_corr=self.use_degree_correlation,
                overlap=self.allow_overlap,
                state_args=dict(recs=[weights],
                                rec_types=[self.weight_model])
            )
        else:
            self.model_ = self._model_fit_function()(
                graph,
                deg_corr=self.use_degree_correlation,
                overlap=self.allow_overlap
            )
        return self._detect_communities()

    def _detect_communities(self):
        if self.nested:
            lowest_level = self.model_.get_levels()[0]
        else:
            lowest_level = self.model_

        number_of_communities = lowest_level.get_B()
        if self.allow_overlap:
            # the overlaps block returns
            # membership vector, and also edges vectors, we need just the membership here at the moment
            membership_vector = list(lowest_level.get_overlap_blocks()[0])
        else:
            membership_vector = list(lowest_level.get_blocks())

        if self.allow_overlap:
            return _overlapping_membership_to_list_of_communities(membership_vector, number_of_communities)


        return _membership_to_list_of_communities(membership_vector, number_of_communities)