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?

regards
Thomas

1 Like

Hi @thomas_stuempfi,
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?

Cheers,

JB.

1 Like

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
Thomas

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:    <http://www.w3.org/2001/XMLSchema#>
PREFIX  dc:     <http://purl.org/dc/elements/1.1/>
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> | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | <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> | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | <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?

JB

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
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Model.html?is-external=true
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
Thomas

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!

I agree with that understanding of leverage cypher. However, I am trying to achieve on handling of multiple XSDs for converting in RDF. how is this doable in the context of without using SPARQL.

Regards,
Paritosh

can you send an example of what you're trying to do so we can find a cypher + n10s based equivalent?

@jesus.barrasa My idea is to build semantic query engine for analytics, mlops/ intent to use industry reference schemas like
1685-2014 JEP30: Part Model Guidelines | JEDEC
Open Applications Group (OAGIS) XML Schema Documentation
and many more applications schema like PLM, ERP, CAD, CAM to define pvt application ontology.
Private ontology will use Common core ontology and Domain reference ontologies example: CHAMP/IOF talk 7.6.18 PLC Overview .pptx at master · NCOR-US/CHAMP · GitHub

I went through tutorials and documentation of neo4j, it is helping. However, I need someone to validate my approach of maintaining vocabularies and XSD schema to make set of microservices for responding to events and messaging. Is there any methodology or enterprising approach like step1) setup tools, step 2) load XSD for this you need to develop pvt library step 3) import ontology in separate schema step 4) integrate using N10s plugin with tools SHACL, OWL2, OTTR with Neo4j. 5) use Middleware for analytics and data streaming.

Sounds like you have a plan!
There will be no better validation than building a prototype to test your approach.
Regarding query endpoint, it would be Cypher or GraphQL based instead of SPARQL (but equally semantic).
There is also the option of using the n10s.rdf.export.spo method which allows for subject,predicate,object querying.

JB