本文整理汇总了Python中halp.directed_hypergraph.DirectedHypergraph.get_node_attributes方法的典型用法代码示例。如果您正苦于以下问题:Python DirectedHypergraph.get_node_attributes方法的具体用法?Python DirectedHypergraph.get_node_attributes怎么用?Python DirectedHypergraph.get_node_attributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类halp.directed_hypergraph.DirectedHypergraph
的用法示例。
在下文中一共展示了DirectedHypergraph.get_node_attributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_node_attributes
# 需要导入模块: from halp.directed_hypergraph import DirectedHypergraph [as 别名]
# 或者: from halp.directed_hypergraph.DirectedHypergraph import get_node_attributes [as 别名]
def test_get_node_attributes():
node_a = 'A'
node_b = 'B'
node_c = 'C'
attrib_c = {'alt_name': 1337}
node_d = 'D'
attrib_d = {'label': 'black', 'sink': True}
# Test adding unadded nodes with various attribute settings
H = DirectedHypergraph()
H.add_node(node_a)
H.add_node(node_b, source=True)
H.add_node(node_c, attrib_c)
H.add_node(node_d, attrib_d, sink=False)
assert H.get_node_attributes(node_a) == {}
assert H.get_node_attributes(node_d) == {'label': 'black', 'sink': False}
# Test getting non-existent node's attributes
try:
H.get_node_attributes("X")
assert False
except ValueError:
pass
except BaseException as e:
assert False, e
示例2: test_to_networkx_digraph
# 需要导入模块: from halp.directed_hypergraph import DirectedHypergraph [as 别名]
# 或者: from halp.directed_hypergraph.DirectedHypergraph import get_node_attributes [as 别名]
def test_to_networkx_digraph():
H = DirectedHypergraph()
H.read("tests/data/basic_directed_hypergraph.txt")
G = directed_graph_transformations.to_networkx_digraph(H)
H_nodes = H.get_node_set()
G_nodes = G.node.keys()
assert H_nodes == set(G_nodes)
H_nodes_attributes = [H.get_node_attributes(node) for node in H_nodes]
for node in G_nodes:
assert G.node[node] in H_nodes_attributes
for hyperedge_id in H.hyperedge_id_iterator():
tail_set = H.get_hyperedge_tail(hyperedge_id)
head_set = H.get_hyperedge_head(hyperedge_id)
for tail_node in tail_set:
for head_node in head_set:
assert G[tail_node][head_node]
# Try transforming an invalid directed hypergraph
try:
directed_graph_transformations.to_networkx_digraph("invalid H")
assert False
except TypeError:
pass
except BaseException as e:
assert False, e