library(RNeo4j)graph = startGraph("http://localhost:7474/db/data/")clear(graph)data = data.frame(Origin = c("SFO", "AUS", "MCI"), FlightNum = c(1, 2, 3), Destination = c("PDX", "MCI", "LGA"))query = "MERGE (origin:Airport {name:{origin_name}})MERGE (destination:Airport {name:{dest_name}})CREATE (origin)<-[:ORIGIN]-(:Flight {number:{flight_num}})-[:DESTINATION]->(destination)"t = newTransaction(graph)for (i in 1:nrow(data)) { origin_name = data[i, ]$Origin dest_name = data[i, ]$Dest flight_num = data[i, ]$FlightNum appendCypher(t, query, origin_name = origin_name, dest_name = dest_name, flight_num = flight_num)}commit(t)cypher(graph, "MATCH (o:Airport)<-[:ORIGIN]-(f:Flight)-[:DESTINATION]->(d:Airport) RETURN o.name, f.number, d.name")在这里,我形成一个Cypher查询,然后遍历数据帧并将值作为参数传递给Cypher查询.您现在的尝试会很慢,因为您正在为创建的每个节点发送一个单独的HTTP请求.通过使用事务终结点,您可以在单个事务下创建多个事物.如果您的数据框很大,那么每笔交易我会将其分成大约1000行.Here, I form a Cypher query and then loop through a data frame and pass the values as parameters to the Cypher query. Your attempts right now will be slow, because you're sending a separate HTTP request for each node created. By using the transactional endpoint, you create several things under a single transaction. If your data frame is very large, I would split it up into roughly 1000 rows per transaction.作为第二次尝试,您应该考虑在neo4j-shell中使用LOAD CSV.As a second attempt, you should consider using LOAD CSV in the neo4j-shell. 这篇关于如何使用向量或数据框在RNeo4j中创建节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-03 11:51