graph.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:thinkgraph 作者: ryanfreckleton 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号