本文整理汇总了Python中networkx.Graph.get_edge_data方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.get_edge_data方法的具体用法?Python Graph.get_edge_data怎么用?Python Graph.get_edge_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.Graph
的用法示例。
在下文中一共展示了Graph.get_edge_data方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LangGraph
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import get_edge_data [as 别名]
#.........这里部分代码省略.........
#add the new type
types.add(type)
self.graph[start][end][TYPES] = types
def removeType(self, start, end, edgeType):
"""
Removes the type on the edge
"""
for prefix in [PARENT, CHILD]:
edgeType = removePrefix(prefix, edgeType)
types = self.graph[start][end][TYPES]
#if the types contains the edge, remove
if edgeType in types:
types.remove(edgeType)
def hasType(self, start, end, type):
"""
Returns true if the edge between the two nodes has the given
type
"""
return type in self.edgeTypes(start, end)
def singleEdgeTypes(self, start, end):
"""
Returns the types on the edge if any, or an empty set is returned
"""
#make sure we are using instances rather than indexes
start = self.indexToInst(start)
end = self.indexToInst(end)
data = self.graph.get_edge_data(start,end)
result = set()
#if there is data, get the types
if data is not None:
result = data.get(TYPES, set())
return result
def edgeTypes(self, start, end):
"""
Returns the types on the edge if any, or an empty set is returned
"""
if self.isDirected:
parent = addPrefixes(PARENT, self.singleEdgeTypes(end, start))
child = addPrefixes(CHILD, self.singleEdgeTypes(start, end))
types = parent.union(child)
else:
types = self.singleEdgeTypes(start, end)
return types
def allEdgeTypes(self):
"""
Returns all the edge types
"""
results = set()
#collect all the edges with all the types
for s,e,types in self.allEdges():
#look up the edge types to make sure everything is covered