def color_graph(graph, colors): G = nx.Graph() for node in graph.get_nodes(): G.add_node(node.get_word()) for node in graph.get_nodes(): for neighbour_node in node.get_neighbours(): G.add_edge(node.get_word(), neighbour_node.get_word()) groups = best_partition(G) for node in graph.get_nodes(): node.set_color(colors[groups[node.get_word()]])
def color_graph(self, graph): G = nx.Graph() for node in graph.get_nodes(): G.add_node(node.get_word()) for node in graph.get_nodes(): for neighbour_node, _weight in node.get_neighbours(): G.add_edge(node.get_word(), neighbour_node.get_word()) groups = best_partition(G) communities = self.merge_converging_communities(groups) for node in graph.get_nodes(): node.set_color(communities[node.get_word()])