I’ve been involved in a few projects at work over the last couple of years that have made use of Semantic Web technologies (triple stores, RDF, OWL, SPARQL etc). For most of these I’ve made of ARC, a really great PHP library by Ben Nowack for interacting with RDF and triple stores. As great as ARC is, it does have a few drawbacks such as being limited to MySQL triple stores, some issues with OPTIONAL queries and it doesn’t entirely support the SPARQL specification.
For these reasons and for general flexibility, my current project wanted to be able to easily swap the underlying triple store from ARC to Jena as needed so I needed to investigate how to expose a Jena triple store as a SPARQL endpoint. After working this out, I now really really appreciate how easy ARC makes this.
Jena doesn’t appear to ship with the ability to expose the ARQ SPARQL processor as a SPARQL endpoint and hence you need to make use of a separate piece of software called Joseki. The following is the list of things I needed to do to get this working in my environment. Note that your setup may have different requirements and also I may have completely misunderstood the best way of doing this!
- Setup a database to use as your triple store and get a JDBC driver so Joseki can interact with it from Java
- Download and extract Joseki
- Add the JDBC driver to the Joseki classpath (e.g. for Windows by adding the following line to
bin\joseki_path.bat
:set CP=%CP%;C:\my_jdbc_driver\my_jdbc_driver.jar
) - Add the following to joseki-config.ttl:
rdf:type joseki:Service ; rdfs:label "My Project SPARQL/Update" ; joseki:serviceRef "sparql/myproject/update" ; joseki:dataset ; joseki:processor joseki:ProcessorSPARQLUpdate . rdf:type joseki:Service ; rdfs:label "SPARQL" ; joseki:serviceRef "sparql/myproject/read" ; joseki:dataset ; joseki:processor joseki:ProcessorSPARQL_FixedDS . rdf:type ja:RDFDataset ; rdfs:label "My Project" ; ja:defaultGraph . rdf:type ja:RDBModel ; ja:connection [ ja:dbType "MySQL" ; ja:dbURL ; ja:dbUser "myproject-database-username" ; ja:dbPassword "myproject-database-password" ; ja:dbClass "com.mysql.jdbc.Driver" ] ; ja:reificationMode ja:minimal ; ja:modelName "DEFAULT" .
- Set the
JOSEKIROOT
environment variable to the location you extracted Joskei - Run Joseki (from it’s directory) by executing
bin/rdfserver.bat
Note that I wanted to be able to make use of SPARUL to update data using the SPARQL endpoint. In ARC I can use SPARQL+ (which is effectively the same for my purposes) on the same endpoint as normal SPARQL queries. For Joseki however, I needed to expose two different endpoints, one for standard SPARQL queries and one for updating.
The one thing I haven’t yet worked out how to do it to be able to use named graphs in my Jena triple store when inserting data. I discovered that the SPARUL update specification requires you to create the graph first (unlike ARC’s SPARQL+) but executing e.g. CREATE GRAPH <http://mygraph/>
seems to fail silently as any following INSERT INTO <http://mygraph/>
statement fails saying that the graph doesn’t exist. Something to keep investigating. It may be something to do with support for the different types of Jena store (RDB, SDB, TDB, etc) which I don’t fully understand yet (I think my instructions above are using RDB which appears to be old but I couldn’t get TDB or SDB working at all).
So all in all I’m pleased to have worked out how to set this up but I will most certainly continue to use ARC where possible as Jena environments seem unnecessarily complex (although this might simply be because it tends to support the W3 specifications fully!).
Hmm. Is there no way to just create a Jena Model, maybe an inference model, in Java, and then create an endpoint that fetches data from that Model?
Hey Martin. I imagine you could do something like that but I already had a MySQL database and was using Joseki to avoid having to write any Java. That's probably the right way to try though.
Hi.
I am new in Joseki. I try to get data from my local database by joseki sparql endpoint (http://localhost:2020/sparql). However, query does not return any data even if for simple queries like “Select ?s ?p ?o Where { ?s ?p ?o. }”. How can I fix it ?
Have you tried setting Joseki up using the quickstart instructions (http://www.joseki.org/start.html) and does that result in something running on port 2020? For your local database setup, maybe try some of the instructions here: http://www.joseki.org/configuration.html
Hi.
Thanks a lot. I solved that problem.
But now I face with a new issue. I need to merge to sparql results which is one set from “dbpedia” and another set from my localhost. So, I tried to run queries for my local store from an external server like “http://www.sparql.org/query.html”. It didn’t work. How can make my local store accesible from remote external services through joseki ?
If I understand your problem correctly, you need to expose your Joseki installation on the public Internet. sparql.org will interpret ‘localhost’ as itself, not your local server.
Hii..Im new to joseki..i have followed the instruction set given stating set the josekiroot and the classpath including all the libraries in joseki-3.4.4\bin..next when i tried to execute rdfserver.bat i get an error stating: The system cannot find the specified path. Error: could not find or load main class files\joseki-3.4.4\etc\log4j.properties. please help me.
I just learned that #mem (and obviously #jdbc) datasets are not supported. In Joseki-3.4.1 the creation of named graphs are supported with TDB 0.8.3 (0.8.5 will not work) datasets. See http://openjena.org/wiki/TDB for more information for downloads and joseki integration.
Thanks Thomas – useful info.
“Here air jordan 21 products xx, has fashion model, superior quality and service, cheap price and updates quickly.I support strongly always! I want to buy XX, I hesitate to select which style more better.Hope your unique recommends.
“
“Here air jordan 21 products xx, has fashion model, superior quality and service, cheap price and updates quickly.I support strongly always! I want to buy XX, I hesitate to select which style more better.Hope your unique recommends.
“
“Here air jordan 21 products xx, has fashion model, superior quality and service, cheap price and updates quickly.I support strongly always! I want to buy XX, I hesitate to select which style more better.Hope your unique recommends.
“
“Here air jordan 21 products xx, has fashion model, superior quality and service, cheap price and updates quickly.I support strongly always! I want to buy XX, I hesitate to select which style more better.Hope your unique recommends.
“
Hi, Do you have any example about sending Sparql Update request to a Joseki server programmatically in Java?Thank you.
Sorry, all my interaction with the servers was using ARC which is PHP-based. I assume this can be achieved with Jena using Joseki as a SPARQL endpoint so probably worth checking out the Jena documentation.
I´m trying to send queries using PHP to a Sparql endpoint using Koseki. But I still not understand how should i interact with the remote Server. Should i send the queries to the follwing adresse: http://localhost/joseki/sparql? i tried it but it doesn´t work! Do you have any idea?
Martin
Hi Martin. I think by default Joseki starts a server on port 2020 at the following endpoint: http://localhost:2020/sparql
Does that work for you?
Something to keep investigating. It may be something to do with support for the different types of Jena store
hi! I’m trying to use Joseki with tdb. Anyone knows if it is possible to invoke SPARQL queries to tdb triple store directly with php pages??
Or I must use the joseki gui or command line?
or also directly also from sdb dataset..
Joseki implements the SPARQL protocol (http://www.w3.org/TR/rdf-sparql-protocol/ ) so you should just be able to execute HTTP requests from PHP (using fopen or curl) to your SPARQL endpoint. See http://www.joseki.org/protocol.html for details. I would assume the Joseki GUI and command line just interact with this endpoint but I’ve not actually checked.
Thank you very much I’ll try it as soon as possible.
Ok now I’m able to invoke and save the triple results of a Query Sparql. But you know if it’s possible to save also the format of results that Joseki realize? With the html interface of Joseki the output is in xml with xsl trasformation. For example with the request ( http://localhost:2020/sparql?query=SELECT+*+{+%3Fs+%3Fd+%3Ff+}%0D%0A&default-graph-uri=&output=xml&stylesheet=sparqlxml2exhibitjson.xsl ) with joseki interface in the browser I have the data in xml with xsl transformation in Json formats. Is possible to get this format also with curl?
thank you
You can use the HTTP Accept header to specify the required output format, or use the ‘accept’ URL parameter. See http://www.joseki.org/protocol.html for details.
great! It works properly. Now I’ll try to manage the Sdb triple store with php..
Anyone knows if I can integrate a reasoner such as Pellet to infere new triple?? and how?
I’m using Joseki with sdb triple store.
I suppose that I have to set properly the config file of Joseki but how?
Sorry, that one I don’t know the answer too. I believe it can be done but I’ve no idea how much can be easily automated.
It is always good you should definitely only be informed but also required!
Hi,
Can you use Joseki + Terp Syntax ? I only can to perform querys with SPARQL .
Thanks
—
Rodrigo
Sorry Rodrigo, I’ve not heard of Terp and don’t know whether you can use it with Joseki. I would assume not.
Gareth i am new to joseki , i have tried everything to create a joseki endpoint but i am not able to do it.
Can you help ??
Hii..Im new to joseki..i have followed the instruction set given stating set the josekiroot and the classpath including all the libraries in joseki-3.4.4\bin..next when i tried to execute rdfserver.bat i get an error stating: The system cannot find the specified path. Error: could not find or load main class files\joseki-3.4.4\etc\log4j.properties. please help me.
Hi, sorry but it’s been a long time since I’ve done any work with Joseki and even then it was fairly minimal. It sounds like your classpath isn’t set correctly so I’d check that first. Otherwise, maybe the Joseki mailing list or other support sources could help? http://www.joseki.org/support.html
I have checked the classpath and it is correct but still iam not able to run joseki..i have followed the instructions but it is of no help..
and thank you for your advice..
I would suggest posting to the Joseki mailing list linked from that support page. There should be Joseki experts listening to that who might be able to help you.