예제 #1
0
def test_relabel_isolated_nodes_to_same():
    """failed after switching to dg.relabel_nodes"""
    G = Graph()
    G.add_nodes_from(range(4))
    mapping = {1: 1}
    H = relabel_nodes(G, mapping, copy=False)
    assert sorted(H.nodes()) == list(range(4))
예제 #2
0
def test_relabel_nodes_multidigraph():
    """failed after switching to dg.relabel_nodes"""
    G = MultiDiGraph([('a', 'b'), ('a', 'b')])
    mapping = {'a': 'aardvark', 'b': 'bear'}
    G = relabel_nodes(G, mapping, copy=False)
    assert sorted(G.nodes()) == ['aardvark', 'bear']
    assert sorted(G.edges()) == [('aardvark', 'bear'), ('aardvark', 'bear')]
예제 #3
0
def test_relabel_nodes_copy():
    """failed after switching to dg.relabel_nodes"""
    G = empty_graph()
    G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'C'), ('C', 'D')])
    mapping = {'A': 'aardvark', 'B': 'bear', 'C': 'cat', 'D': 'dog'}
    H = relabel_nodes(G, mapping)
    assert sorted(H.nodes()) == ['aardvark', 'bear', 'cat', 'dog']
예제 #4
0
def test_relabel_nodes_function():
    """failed after switching to dg.relabel_nodes"""
    G = empty_graph()
    G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'C'), ('C', 'D')])

    # function mapping no longer encouraged but works
    def mapping(n):
        return ord(n)

    H = relabel_nodes(G, mapping)
    assert sorted(H.nodes()) == [65, 66, 67, 68]
예제 #5
0
파일: paula.py 프로젝트: ccolonna/R2R
    def __make_xpointer_compatible(self):
        """
        ensure that all node and IDs in the document graph are valid
        xpointer IDs. this will relabel all node IDs in place in the discourse
        graph and change its ``.tokens`` list accordingly.
        """

        node_id_map = {node: ensure_xpointer_compatibility(node)
                       for node in self.dg.nodes_iter()}

        old_token_ids = self.dg.tokens
        # replace document graph with node relabeled version
        self.dg = relabel_nodes(self.dg, node_id_map, copy=True)
        self.dg.tokens = [node_id_map[tok] for tok in old_token_ids]
예제 #6
0
def test_relabel_nodes_missing():
    G = Graph([('A', 'B'), ('A', 'C'), ('B', 'C'), ('C', 'D')])
    mapping = {0: 'aardvark'}
    with pytest.raises(KeyError) as excinfo:
        G = relabel_nodes(G, mapping, copy=False)
예제 #7
0
def test_relabel_nodes_digraph():
    """failed after switching to dg.relabel_nodes"""
    G = DiGraph([('A', 'B'), ('A', 'C'), ('B', 'C'), ('C', 'D')])
    mapping = {'A': 'aardvark', 'B': 'bear', 'C': 'cat', 'D': 'dog'}
    H = relabel_nodes(G, mapping, copy=False)
    assert sorted(H.nodes()) == ['aardvark', 'bear', 'cat', 'dog']