From 6631553ad20e9423639dd2c0d5b5734b3f5b89c4 Mon Sep 17 00:00:00 2001 From: giuliorossetti Date: Tue, 12 Mar 2019 10:18:58 +0100 Subject: [PATCH] :bug: node perception graph conversion --- cdlib/algorithms/overlapping_partition.py | 7 +++++++ cdlib/test/test_community_discovery_models.py | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/cdlib/algorithms/overlapping_partition.py b/cdlib/algorithms/overlapping_partition.py index db0c0e0f..54d8eec1 100644 --- a/cdlib/algorithms/overlapping_partition.py +++ b/cdlib/algorithms/overlapping_partition.py @@ -146,11 +146,18 @@ def node_perception(g, threshold, overlap_threshold, min_comm_size=3): """ g = convert_graph_formats(g, nx.Graph) + tp = type(list(g.nodes())[0]) with suppress_stdout(): np = NodePerception(g, sim_threshold=threshold, overlap_threshold=overlap_threshold, min_comm_size=min_comm_size) coms = np.execute() + if tp != str: + communities = [] + for c in coms: + c = list(map(tp, c)) + communities.append(c) + coms = communities return NodeClustering(coms, g, "Node Perception", method_parameters={"threshold": threshold, "overlap_threshold": overlap_threshold, diff --git a/cdlib/test/test_community_discovery_models.py b/cdlib/test/test_community_discovery_models.py index 2af421f8..369bb9a4 100644 --- a/cdlib/test/test_community_discovery_models.py +++ b/cdlib/test/test_community_discovery_models.py @@ -41,6 +41,14 @@ def test_node_perception(self): self.assertEqual(type(coms.communities[0]), list) self.assertEqual(type(coms.communities[0][0]), str) + g = nx.karate_club_graph() + + coms = algorithms.node_perception(g, threshold=0.25, overlap_threshold=0.25) + self.assertEqual(type(coms.communities), list) + if len(coms.communities) > 0: + self.assertEqual(type(coms.communities[0]), list) + self.assertEqual(type(coms.communities[0][0]), int) + def test_angel(self): g = get_string_graph() coms = algorithms.angel(g, threshold=0.25)