当前位置: 首页>>代码示例>>Python>>正文


Python AGraph.edges方法代码示例

本文整理汇总了Python中pygraphviz.AGraph.edges方法的典型用法代码示例。如果您正苦于以下问题:Python AGraph.edges方法的具体用法?Python AGraph.edges怎么用?Python AGraph.edges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygraphviz.AGraph的用法示例。


在下文中一共展示了AGraph.edges方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_graphviz

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import edges [as 别名]
 def get_graphviz(self, triple_hook=graphviz_triple_hook,
                  node_hook=graphviz_node_hook,
                  theme_options=VIS_THEME_OPTIONS, **hook_options):
     """
     Create a pygraphviz graph from the tree
     @param triple_hook: a function that returns an attribute dict (or None)
                         given a triple and the kargs
     @param node_hook: a function that returns a label given a node
                        and the kargs
     @param theme_options: a dict-of-dicts containing global
                           graph/node/edge attributes
     @param hook_options: additional arguments to pass to the hook functions
     """
     def _id(node):
         return node.uri.split("/")[-1]
     g = AGraph(directed=True, strict=False)
     triples = list(self.get_triples())
     # create nodes
     nodeset = set(chain.from_iterable((t.subject, t.object)
                                       for t in triples))
     for n in sorted(nodeset, key=lambda n:n.id):
         g.add_node(_id(n), **node_hook(n, **hook_options))
     connected = set()
     # create edges
     for triple in sorted(triples, key=lambda t:t.predicate):
         kargs = triple_hook(triple, **hook_options)
         if kargs:
             if kargs.get('reverse'):
                 g.add_edge(_id(triple.object), _id(triple.subject), **kargs)
             else:
                 g.add_edge(_id(triple.subject), _id(triple.object), **kargs)
             connected |= {_id(triple.subject), _id(triple.object)}
     connected = chain.from_iterable(g.edges())
     for isolate in set(g.nodes()) - set(connected):
         g.remove_node(isolate)
     # some theme options
     for obj, attrs in theme_options.iteritems():
         for k, v in attrs.iteritems():
             getattr(g, "%s_attr" % obj)[k] = v
     return g
开发者ID:vanatteveldt,项目名称:syntaxrules,代码行数:42,代码来源:syntaxtree.py

示例2: igraph_from_dot

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import edges [as 别名]
def igraph_from_dot(file):
    """numbered_graph(file) -> graph

  Input:
    file: the name of the dot-file 

  Output:
    graph: igraph.Graph object. Verticies has the attribute
         "name".
    """
    print("Step 1/3: Reading from dot.")
    a=AGraph(file)
    vertices = a.nodes()
    edges = a.edges()
    numbered_edges = []
    print("Step 2/3: To numbered graph. Be patient...")
    for x, y in edges:
        xx = vertices.index(x)
        yy = vertices.index(y)
        numbered_edges.append((xx,yy))
    print("Step 3/3: To igraph.")
    g=igraph.Graph(len(vertices), numbered_edges)
    g.vs["name"]=vertices
    return g
开发者ID:horvatha,项目名称:cxnet,代码行数:26,代码来源:igraphtools.py


注:本文中的pygraphviz.AGraph.edges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。