def rm_node(hie, g_id, parent, node_id, force=False):
"""remove a node from a graph """
if isinstance(hie.node[g_id], GraphNode):
if [c for c in all_children(hie, g_id)
if node_id in hie.edge[c][g_id].mapping.values()]:
if not force:
raise ValueError(
"some nodes are typed by {}"
"set the force argument to"
"delete the as well"
.format(node_id))
lhs = nx.DiGraph()
lhs.add_node(node_id)
ppp = nx.DiGraph()
rhs = nx.DiGraph()
rule = Rule(ppp, lhs, rhs)
_rewrite(hie, g_id, rule, {node_id: node_id})
elif isinstance(hie.node[g_id], RuleNode):
hie.node[g_id].rule.remove_node_rhs(node_id)
for _, typing in hie.out_edges(g_id):
if node_id in hie.edge[g_id][typing].rhs_mapping.keys():
del hie.edge[g_id][typing].rhs_mapping[node_id]
else:
raise ValueError("node is neither a rule nor a graph")
评论列表
文章目录