예제 #1
0
    def setUp(self):
        g = DirectedGraph()
        edges = [(1, 0), (2, 0), (3, 1), (4, 1), (5, 2), (6, 1), (7, 0), (8, 0), (9, 8)]
        for u, v in edges:
            g.add_node(u, title=u)
            g.add_node(v, title=v)
            g.add_edge(u, v)

        self.g = g
예제 #2
0
    def setUp(self):
        g = DirectedGraph()
        edges = [(0, 3), (0, 4), (0, 5), (0, 6),
                 (1, 8), (2, 8), (2, 1), (2, 4),
                 (2, 6), (2, 0), (3, 1), (3, 2),
                 (3, 6), (3, 7), (3, 8), (3, 9),
                 (4, 3), (6, 1), (6, 9), (7, 0),
                 (7, 1), (7, 2), (7, 4), (7, 5),
                 (7, 6), (8, 1), (8, 2), (9, 8),
                 (9, 2), (9, 4)]
        for u, v in edges:
            g.add_node(u, title=u)
            g.add_node(v, title=v)
            g.add_edge(u, v)

        self.g = g
예제 #3
0
def build_graph(args, index_map):
    graph = DirectedGraph()

    with open(args.pages_xml) as fh:
        for page in WikipediaXmlReader(fh, NAMESPACE.format(args.namespace_version)):
            if page.title not in index_map:
                continue

            for link in page.links:
                u = index_map[page.title]["id"]
                if link in index_map:
                    graph.add_node(u, title=page.title, text_len=index_map[page.title]["text_len"])
                    v = index_map[link]["id"]
                    graph.add_node(v, title=link, text_len=index_map[link]["text_len"])
                    graph.add_edge(u, v)

    return graph
예제 #4
0
 def test_add_node(self):
     g = DirectedGraph()
     g.add_node(0, title='foo', text_length=10)
     self.assertEqual(g[0], {'text_length': 10, 'title': 'foo'})