Sparql for neo4j

Hi all,
i know that in neo4j 2.x there was once a sparql endpoint in development.
Jessus Baressa does a wonderfull job in semantics.

How would you enable neo4j (e.g develop a driver that turns a subset of a database into jena dataset ) to be queried via sparql? I would like to avoid data douplication.
I mean i could write a restservice reading the RDF Triples from a cypherquery trough neosemantix service and use the two service parameters as input (one the cypher string, two the sparql string), but is this a viable approach? What about upates through sparql?


1 Like

Hi @thomas.stuempfig,
We have no immediate plans to support SPARQL in neosemantics unfortunately. Essentially because we have Cypher that covers the need for a structured graph query language. Is cypher not an option for you?

If you don't want to export the data as RDF and import it into Jena, the only option I can think of is the development of a SPARQL endpoint as an extension to Neo4j. Is that a project you'd be willing to undertake? If that's the case I'd love to hear about it.

If not, maybe you can share a bit more about what you're trying to achieve and maybe we can find some workaround?



Hi Jesus,
thank you very much for your attention. Well what i am trying to achive is making neo4j data avaible for systems that do not know of cypher but are able to execute sparql queries.
I like cypher very much and labeld graphs are far more easy to work with in my opinion. Nontheless
there is one very good reason for rdf ontologies OWL priciple of open world logic is quite intreaging me and probably one possible way of building distributed configuration engines.
Well imagine once you have a car configurator with its logic, but refering to foreign ontologies of a tire supplier. If both of them would describe their ontologies in owl they will be naturaly (formaly at least) compatible and you can reason upon both of them. I am not aware of such logic within neo4j. This is why i ask for a sparql 1.1 endpoint.
The other approach is jbpm. I actualy explore both, and already have a working jbpm/drools work item handler executing cypher calls to neo4j with the java driver (my other question in this forum since i have warnings).

Best regards

1 Like

Hi all,
meanwhile i installed neo4j 4.0.1 and jena 3.13.1
i also installed the n10s plugin and mounted the /rdf http methods
then I was able to do the following sparql query with jena on windows.
i created some adresses
create (n1:Adress {street:"Street3",town:"Hamburg",postcode:"2000",country:"Germany"}) return n1
create (n1:Adress {street:"Street1",town:"Berlin",postcode:"1000",country:"Germany"}) return n1
create (n1:Adress {street:"Street2",town:"Berlin",postcode:"1000",country:"Germany"}) return n1

apache-jena-3.13.1\bat\sparql.bat --data http://demo:demo@localhost:7474/rdf/thomas/describe/find/Adress/country/Germany --query query.rq

with query.rq

PREFIX  xsd:    <>
PREFIX  dc:     <>
PREFIX  :       <.>

SELECT ?s ?a ?b
    { ?s ?p "Berlin" }
	{?s ?a ?b}

gave me the following result :smile:

now it is only a matter to create a small web service wrapper converting an http get to http post /rdf/thomas/cypher with the query as content....
ok ... this will limit the queries to 2k or at best ~8k but jena can't do --data with http post.

this proofes that one can do sparql queries against subgraphes of neo4j :smile: .

thank you Jesus and the team to provide such a cool plugin.

| s                             | a                                                 | b                           |
| <neo4j://individuals#1833273> | <> | <neo4j://vocabulary#Adress> |
| <neo4j://individuals#1833273> | <neo4j://vocabulary#postcode>                     | "1000"                      |
| <neo4j://individuals#1833273> | <neo4j://vocabulary#town>                         | "Berlin"                    |
| <neo4j://individuals#1833273> | <neo4j://vocabulary#country>                      | "Germany"                   |
| <neo4j://individuals#1833273> | <neo4j://vocabulary#street>                       | "Street 1"                  |
| <neo4j://individuals#1833274> | <> | <neo4j://vocabulary#Adress> |
| <neo4j://individuals#1833274> | <neo4j://vocabulary#postcode>                     | "1000"                      |
| <neo4j://individuals#1833274> | <neo4j://vocabulary#town>                         | "Berlin"                    |
| <neo4j://individuals#1833274> | <neo4j://vocabulary#country>                      | "Germany"                   |
| <neo4j://individuals#1833274> | <neo4j://vocabulary#street>                       | "Street2"                   |
1 Like

Hi Thomas, that's very interesting.
Can you share pointers to Jena doc where it describes how the sparql.bat process works?
Is it loading the RDF out of Neo4j first and then running the SPARQL on an in memory view of the data?


1 Like

Hi Jesus,
i took just the tutorial from jena.
Jena Totorials
the sparql.bat is more or less the following code

java -cp 'DIST/lib/*' arq.sparql ...

DIST being the distribution of jena.
As far as i understand, jena is just building an in memory dataset from the rdf content in the url followed by parsing and executing the sparql.
when looking into the Jena API Documentation you find
the Model read(String url) Method,
This made me hope just to pass a url as --data option to arq.sparql. And voilà it just works.
As far as i can see, this is in memory, i did not see any temporary file on disk.

Ok, this method has it's limits.But still is probably a path for a bridge in some cases. I will do further research on the topic since my ultimate goal is distributed reasoning e.g. pushing inference results to different destination systems.

best regards

Hello, in my case I would find this plugin/extension useful because I use SPARQL to access WikiMedia RDF on Blazegraph, so it could be a good way to get the best of the two worlds.
So I think it would be worth to provide such integration as a plugin.

Thank you!