Exemple #1
0
def main(args):
    with io.open(args.file) as f:
        edges = list(parse_graph(f))
    g = Graph(edges)
    scores = g.page_rank()
    print(">" * 80)
    for node, score in sorted(scores.items(), key=lambda x: x[1],
                              reverse=True):
        print("{} ({})".format(node, score))
    print("<" * 80)
Exemple #2
0
 def test_my2(self):
     edges = [
         ["A", "B"],
         ["B", "C"],
         ["C", "A"],
         ["C", "B"],
         ["C", "D"],
     ]
     g = Graph(edges)
     # scores se espera que sea {nodo1: score1, nodo2: score2, ...}
     scores = g.page_rank(damping=0.85, limit=1.0e-8)
     sorted_nodes = [node for node, _ in sorted(scores.items(), key=lambda x: x[1], reverse=True)]
     self.assertSequenceEqual(sorted_nodes, ["C", "B", "A", "D"])