Exemple #1
0
    def open(self, rebuild_index):
        self.db = plyvel.DB(self.path, create_if_missing=True)

        self.graph = cwg.new_graph()

        index_path = os.path.splitext(self.path)[0] + ".index"
        print("MemoryGraph: index path", index_path)
        self.index = hnswlib.Index(space=self.space, dim=self.dim) 

        if os.path.isfile(index_path) and not rebuild_index:
            print("MemoryGraph: loading index")
            self.index.load_index(index_path)
            self.index.set_ef(self.ef)
            self.load_all_node_ids()
        else:
            print("MemoryGraph: building index")
            self.index.init_index(max_elements=self.max_elements, ef_construction=self.ef * 2, M=self.M)
            self.index.set_ef(self.ef)
            self.load_all_nodes()
            if cwg.len(self.graph) > 0:
                self.save()
        
        self.load_all_edges()

        print("MemoryGraph:", self.index.get_current_count(), "nodes")
Exemple #2
0
import community_walk_graph as cwg

graph = cwg.new_graph()
cwg.add_edge(graph, 1, 2)
cwg.add_edge(graph, 2, 3)
cwg.add_edge(graph, 3, 4)
cwg.add_edge(graph, 4, 5)
cwg.add_edge(graph, 5, 6)
cwg.add_edge(graph, 6, 7)
cwg.add_edge(graph, 7, 8)
cwg.add_edge(graph, 8, 9)
cwg.add_edge(graph, 9, 10)
cwg.add_edge(graph, 10, 11)
cwg.add_edge(graph, 11, 12)
cwg.add_edge(graph, 12, 13)
cwg.add_edge(graph, 13, 14)
cwg.add_edge(graph, 14, 15)
cwg.add_edge(graph, 15, 16)
cwg.add_edge(graph, 16, 17)
cwg.add_edge(graph, 17, 18)
cwg.add_edge(graph, 18, 19)
cwg.add_edge(graph, 19, 20)
cwg.add_edge(graph, 20, 1)

communities_result = cwg.communities(graph,
                                     [1, 2, 3, 4, 5, 11, 12, 13, 14, 15], 7,
                                     100, 50)
print(communities_result)