コード例 #1
0
ファイル: test_graph.py プロジェクト: spmacdonald/thistle
    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
ファイル: test_graph.py プロジェクト: spmacdonald/thistle
 def test_add_edge(self):
     g = DirectedGraph()
     g.add_edge(0, 1)
     g.add_edge(0, 1)
     g.add_edge(1, 1)
     g.add_edge(2, 0)
     self.assertEqual(g.predecessors(0), [2])
     self.assertEqual(g.successors(0), [1])
     self.assertEqual(g.predecessors(1), [0, 1])
     self.assertEqual(g.successors(1), [1])
コード例 #3
0
ファイル: test_graph.py プロジェクト: spmacdonald/thistle
    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
コード例 #4
0
ファイル: build_graph.py プロジェクト: spmacdonald/thistle
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
コード例 #5
0
ファイル: test_graph.py プロジェクト: spmacdonald/thistle
 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'})