def __init__(self):
self.index = Index(config.INDEX_PATH)
# Checks if the full graph for this dataset was already ranked.
# If not, run page rank and store the results
pr_file_path = "%s/page_rank/%s.p" % (config.DATA, config.DATASET)
if not os.path.exists(pr_file_path):
g = nx.DiGraph()
g.add_edges_from(model.get_all_edges())
print "Running pageRank with %d nodes." % g.number_of_nodes()
self.pr = nx.pagerank(g)
cPickle.dump(self.pr, open(pr_file_path, "w"))
# Else, just loads it
else:
self.pr = cPickle.load(open(pr_file_path, 'r'))
评论列表
文章目录