cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Passing multiple values to an export query via http

r_moquin
Node Clone

If you have a cypher query that is meant to retrieve an IRI and it's associated relationships as RDF, can you use something like the following to retrieve multiple iris instead of just 1? I was trying to see if I could do something like this through the HTTP interface (didn't try with the n10s procedures yet), but I wasn't successful at figuring it out so far:

unwind ['iri1','iri2'] as iri
match(n:Resource{uri:iri}) return n

Thanks!
Ryan

3 REPLIES 3

Hi Ryan, let me see if I've understood your question.

Let's say I have a simple RDF graph imported into neo4j (using default settings).
What you want to do is select a bunch of nodes by URI and have them serialised as RDF through the n10s cypher endpoint. Is this right?

Here is a step by step example:

//init graph with defaults
call n10s.graphconfig.init();

//(optional) define namespace prefix
call n10s.nsprefixes.add("neo","http://neo4j.org/vocab/sw#");

//Import simple graph
call n10s.rdf.import.fetch("https://raw.githubusercontent.com/jbarrasa/neosemantics/3.5/docs/rdf/nsmntx.ttl","Turtle")

//POST request for the Neo4j browser
:POST http://localhost:7474/rdf/neo4j/cypher
{ "cypher": "unwind ['http://neo4j.org/ind#nsmntx3502','http://neo4j.org/ind#graphql3502'] as uri MATCH (n:Resource {uri: uri}) return n",  "format": "RDF/XML"}

//you can also run it via curl (or postman or any other HTTP API testing tool). Note you'll have to deal with authentication which is implicit when run from the Neo4j browser
curl http://localhost:7474/rdf/neo4j/cypher --data '{ "cypher": "unwind [\"http://neo4j.org/ind#nsmntx3502\",\"http://neo4j.org/ind#graphql3502\"] as uri MATCH (n:Resource {uri: uri}) return n",  "format": "RDF/XML"}' -H 'Authorization: Basic bmVvNGo6bmVv'

In the example I've intentionally set the serialisation format to RDF/XML to pass the generated RDF through the RDF validation service and see the data as an RDF graph:

Basically, you can run any cypher and whatever your cypher query returns will be translated to RDF. Even paths, which I think is pretty cool, btw (let me know if you want me to post an example).

But re-reading your question, I have the impression I've just replicated what you had already done and not really added anything new?

Hope this helps anyway. Let me know.

JB.

And while I'm at it... ...I'll add that you could also pass your list of URIs as a query param which would get better perf and also save you from having to touch the cypher on each request.

Here's how (on the same example)

:POST http://localhost:7474/rdf/neo4j/cypher
{ "cypher": "unwind $urilist as uri MATCH (n:Resource {uri: uri}) return n",  "format": "RDF/XML", "cypherParams" : { "urilist": ["http://neo4j.org/ind#nsmntx3502","http://neo4j.org/ind#graphql3502"]}}


//equivalent curl post request
curl http://localhost:7474/rdf/neo4j/cypher --data '{ "cypher": "unwind $urilist as uri MATCH (n:Resource {uri: uri}) return n",  "format": "RDF/XML",  "cypherParams" : { "urilist": ["http://neo4j.org/ind#nsmntx3502","http://neo4j.org/ind#graphql3502"]}}'  -H 'Authorization: Basic bmVvNGo6bmVv'

Hope this helps.

JB.

r_moquin
Node Clone

Yes, thank you JB, this is very helpful. The first response is essentially what I was trying, but I wanted to do it in the way you did in your second response. I was getting mostly syntactical sounding errors which made me think I wasn't doing it right. Your second example should help me to figure out what I'm doing wrong (I'm still pretty new to Cypher and Neo4j).

Thanks again JB! Congrats on getting 4.x pushed out!

Ryan