r 直接从Neo4j REST API获取图形数据到R.对于R igraph用户有用。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了r 直接从Neo4j REST API获取图形数据到R.对于R igraph用户有用。相关的知识,希望对你有一定的参考价值。

# Requirements
#sudo apt-get install libcurl4-gnutls-dev # for RCurl on linux
#install.packages('RCurl')
#install.packages('RJSONIO')

library('RCurl')
library('RJSONIO')
 
query <- function(querystring) {
  h = basicTextGatherer()
  curlPerform(url="http://localhost:7474/db/data/cypher",
    postfields=paste('query',curlEscape(querystring), sep='='),
    writefunction = h$update,
    verbose = FALSE
  )
  
  result <- fromJSON(h$value())
  
  data <- data.frame(t(sapply(result$data, unlist)))
  names(data) <- result$columns
  
  data 
}
 

# EXAMPLE
# =======

# Cypher Query:
q <- "match (o:Organization)-[r]-(p:Person) return o.name,o.location,p.account,p.name,p.email limit 20"

data <-query(q)

head(data,20)

# Output:
#           o.name                          o.location      p.account         p.name            p.email
# 1     PerfectLine                             Estonia         kritik                                  
# 2      Sappho OSS                           London UK    andrewheald                                  
# 3          The 88                                 NYC         aface1                                  
# 4          The 88                                 NYC     xbilldozer                                  
# 5          The 88                                 NYC         chadyj                                  
# 6          The 88                                 NYC       benmanns Benjamin Manns benmanns@gmail.net
# 7        simplabs                     Munich, Germany        marcoow                                  
# 8   Everyday Hero                 Brisbane, Australia    soloman1124                                  
# 9   Everyday Hero                 Brisbane, Australia         orodio                                  
# 10  Everyday Hero                 Brisbane, Australia justinhennessy                                  
# 11  Everyday Hero                 Brisbane, Australia           coop     Tim Cooper coop@latrobest.org
# 12  Everyday Hero                 Brisbane, Australia      evilmarty   Marty Zalega    marty@zalega.co
# 13 Sorenson Media  Salt Lake City, UT & San Diego, CA       bcarlson                                  
# 14 Sorenson Media  Salt Lake City, UT & San Diego, CA      elmomalmo                                  
# 15 Sorenson Media  Salt Lake City, UT & San Diego, CA        enthooz                                  
# 16         3scale Barcelona, Spain and Sunnyvale, USA          solso                                  
# 17         3scale Barcelona, Spain and Sunnyvale, USA   MarkCheshire                                  
# 18         3scale Barcelona, Spain and Sunnyvale, USA          rhoml                                  
# 19         3scale Barcelona, Spain and Sunnyvale, USA           mikz  Michal Cichra                   
# 20         3scale Barcelona, Spain and Sunnyvale, USA           njyx                                  

以上是关于r 直接从Neo4j REST API获取图形数据到R.对于R igraph用户有用。的主要内容,如果未能解决你的问题,请参考以下文章

Node Js rest api和数据库推荐

哪个 graphdb 用于用户的数据库。 (Neo4j 或 FB 图形 API)

java 使用Neo4j的RESTful API来管理Java中的图形数据

在啥情况下 Neo4J 的 Rest API 会返回 404 Not Found?

neo4j简介

Spring Data REST Neo4j 创建关系