对社交网络分析查询使用NetworkX和库新增功能。通过查询,我的意思是通过边缘创建路径的两个边缘节点的属性来选择/创建子图,并且节点包含属性。该图是使用与通过NetworkX中边缘和节点属性查询图形的最佳实践
for node,data in G2.nodes_iter(data=True):
if (data['type'] == "Cat"):
# get all edges out from these nodes
#then recursively follow using a filter for a specific statement_id
#or get all edges with a specific statement id
# look for with a node attribute of "cat"
查询的形式
G2 = nx.MultiDiGraph()
G2.add_node("UserA", { "type" :"Cat" })
G2.add_node("UserB", { "type" :"Dog" })
G2.add_node("UserC", { "type" :"Mouse" })
G2.add_node("Likes", { "type" :"Feeling" })
G2.add_node("Hates", { "type" :"Feeling" })
G2.add_edge("UserA", 'Hates' , statementid="1")
G2.add_edge("Hates", 'UserB' , statementid="1" )
G2.add_edge("UserC", 'Hates' , statementid="2")
G2.add_edge("Hates", 'UserA' , statementid="2" )
G2.add_edge("UserB", 'Hates' , statementid="3" )
G2.add_edge("Hates", 'UserA' , statementid="3" )
G2.add_edge("UserC", 'Likes' , statementid="3" )
G2.add_edge("Likes", 'UserB' , statementid="3" )
的MultiDiGraph是否有更好的方法来查询?或者是创建自定义迭代来创建子图的最佳实践?
或者(和一个单独的问题),该图可以简化,但我没有使用下面的图,因为“恨”类型的对象将具有预处理器。这会使查询更简单吗?似乎更容易在节点迭代
G3 = nx.MultiDiGraph()
G3.add_node("UserA", { "type" :"Cat" })
G3.add_node("UserB", { "type" :"Dog" })
G3.add_edge("UserA", 'UserB' , statementid="1" , label="hates")
G3.add_edge("UserA", 'UserB' , statementid="2" , label="hates")
其他说明:
- 也许
add_path
增加了一个标识符的路径产生的? - IGRAPH具有 一个nice query feature
g.vs.select()
的例子似乎提供了查找任何节点或边缘的好办法。但要查找节点和边的组合?在你的例子中想象这个查询。 “返回同样具有边的属性为”Color = red“的鱼类节点的子图。是否还有一个用于查询两者的单线程并搜索子图?例如,edges_iter是否返回节点和边? – 2013-03-27 04:35:54