【问题标题】:Parsing vectors from R into cypher query via RCurl with NEO4J's REST API使用 NEO4J 的 REST API 通过 RCurl 将向量从 R 解析为密码查询
【发布时间】:2014-01-14 11:16:38
【问题描述】:

我正在尝试从我的 R 会话向 neo4j 发送查询

查看 neo4j 提供的 REST API 文档:http://docs.neo4j.org/chunked/milestone/rest-api-cypher.html 我在下面制定了一个成功的 curl 查询

curl -X POST -d @test.json http://localhost:7474/db/data/cypher -H "Content-Type: application/json"

其中test.json的内容如下

{"query": "start pathway=node:pathwayid(pathway={pathway}) match pathway--(ko:`ko`)<-[r]-(cpd:`cpd`) return ko.ko,r,cpd.cpd limit 5;","params": {"pathway":"path:ko00010"} }

到目前为止在Use neo4j with R 中给出的解决方案 查询存储在查询字符串中(参见下面的代码),不利用参数化密码查询的能力。例如:

library(RCurl)
library(RJSONIO)

h = basicTextGatherer()

  curlPerform(url="localhost:7474/db/data/ext/CypherPlugin/graphdb/execute_query",
postfields=paste('query',curlEscape(querystring), sep='='),
writefunction = h$update,
verbose = FALSE
)           
result <- fromJSON(h$value())

在这种情况下查询字符串是:

start pathway=node:pathwayid('pathway:"path:ko00010"') match pathway--(ko:`ko`)<-[r]-(cpd:`cpd`) return ko.ko,r,cpd.cpd limit 5;

我很好奇如何将参数解析到 RCurl。

【问题讨论】:

  • 我猜我将不得不更改这部分 r 代码postfields=paste('query',curlEscape(querystring), sep='=')

标签: r rest curl neo4j


【解决方案1】:

改用这个

fromJSON(
getURL("http://localhost:7474/db/data/cypher", 
    customrequest='POST', 
    httpheader=c('Content- Type'='application/json'),
    postfields=toJSON(list(query=q2,params=list(pathway=q3)))
  )
)

代码修改自: http://pastebin.com/FAeJ0b2R

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-29
    • 2018-11-29
    • 1970-01-01
    相关资源
    最近更新 更多