主要目的是从Kaggle上可用的edges.csv数据集中隔离neo4j中的二阶自我图。最初,我使用可用的here指南加载了数据。
看到了this和this,但它们似乎并没有覆盖Neo4j的桥梁。
尝试使用igraph
的简单方法:
library(igraph)
df <- read.csv("edges.csv")
g <- graph_from_edgelist(as.matrix(df),directed = FALSE)
#pull out 2nd order ego graph for Cap
g_ego <- make_ego_graph(g, 2, nodes = which((V(g)$name)=='CAPTAIN AMERICA'))
#extract the graph object
n_g <- g_ego[[1]]
#create an edge list with names like the edges.csv from Kaggle
named_ego <- get.edgelist(n_g, names = TRUE)
write.csv(named_ego, file = "scnd_order_ego.csv")
使用与以上csv指南中相同的密码命令:
USING PERIODIC COMMIT 5000
LOAD CSV WITH HEADERS FROM
"file:///scnd_order_ego.csv" as row
MERGE (h:Hero{name:row.hero})
MERGE (c:Comic{name:row.comic})
MERGE (h)-[:APPEARED_IN]->(c)
CALL apoc.periodic.iterate(
"MATCH (p1:Hero)-->(:Comic)<--(p2:Hero) where id(p1) < id(p2) RETURN p1,p2",
"MERGE (p1)-[r:KNOWS]-(p2) ON CREATE SET r.weight = 1 ON MATCH SET r.weight
= r.weight + 1"
, {batchSize:5000, parallel:false,iterateList:true})
由于我以为自己拔出了合适的自我图,所以我希望看到一个单一的组件图,但是:
R或密码命令中是否缺少明显的东西?
如何隔离neo4j中单个节点的二阶自我图(最好包括如何将其写入可与edges.csv相比较的边缘列表)?