Esempio n. 1
0
def create_text_graph(words_list, colors):
    graph = Graph()
    for i in range(len(words_list)):
        node = graph.get_node(words_list[i])
        for next_node_word in words_list[i + 1 : i + 3]:  # 2 nodes ahead
            next_node = graph.get_node(next_node_word)
            node.connect_to(next_node)
    color_graph(graph, colors)
    return graph
 def create_text_graph(self, text, percentage):
     words_list = self.dictionary.normalize_document(text)
     keywords = self.topicModel.return_top_words(words_list, percentage)
     graph = Graph()
     for i in range(len(words_list)):
         if words_list[i] in keywords:
             node = graph.get_node(words_list[i])
             weight = 4
             for next_node_word in words_list[i + 1:i + 4]: #2 nodes ahead
                 if next_node_word in keywords:
                     next_node = graph.get_node(next_node_word)
                     node.connect_to(next_node, weight)
                     weight -= 1
     graph.remove_single_vertices()
     self.color_graph(graph)
     return graph