使用NetworkX和newtothelibrary进行社交网络分析查询。我所说的查询是指通过边节点的属性来选择/创建子图,边节点在其中创建路径,并且节点包含属性。这个图使用的是这种形式的多向图
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" )
询问
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"
有更好的查询方法吗?或者创建自定义迭代来创建子图是最佳实践吗?
另外(还有一个单独的问题),这个图可以简化,但我不使用下面的图,因为“hates”类型的对象将有前置处理器。这会使查询更简单吗?似乎更容易在节点上迭代
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
会在创建的路径中添加标识符?g.vs.select()
需要首先确保Namenode处于安全模式,以检查以下步骤:
要了解安全模式的状态,请使用命令:
要进入安全模式,请使用命令:
要退出安全模式,请使用命令:
然后重新启动hdfs服务。然后再试着把它放进去。在Hadoop中再次使用jar文件
相关问题 更多 >
编程相关推荐