對社交網絡分析查詢使用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