def create_graph(semantic_graph):
splines = 'spline'
if semantic_graph.loop_edges or semantic_graph.and_loop_edges:
splines = 'ortho'
g = graphviz.Digraph(
graph_attr={'rankdir':'BT', 'splines':splines},
node_attr={
'shape':'rectangle', 'style':'rounded,filled', 'fillcolor':'#FFFFCC'
}
)
for identifier, label, cls in semantic_graph.nodes:
g.node(identifier, label=label, **attrs[cls])
g.edges(semantic_graph.edges)
for e in semantic_graph.and_edges:
g.edge(*e, dir="none")
for e in semantic_graph.loop_edges:
g.edge(*e, constraint="false")
for e in semantic_graph.and_loop_edges:
g.edge(*e, dir="none", constraint="false")
for a, b in semantic_graph.conflicts:
subgraph = graphviz.Digraph('cluster', graph_attr={'rank':'same', 'color':'none'})
subgraph.edge(a, b, style="tapered", dir="both", arrowhead="none",
arrowtail="none", constraint="false", color="red", penwidth="7")
g.subgraph(subgraph)
return g
评论列表
文章目录