And now for the third in a row of triple-store installations. This time it’s Sesame, an open source datastore for RDF and relational data. Thankfully, due to the minimal requirements and the pretty good documentation, the installation was quick and much less painful than expected.
Hardware: Apple Mac Mini (running Mac OS X Lion 10.7), out of the box
I followed mostly the instructions given on http://www.openrdf.org/doc/sesame2/users/. They explain stuff quite well, so it was actually rather enjoyable to read. You can also find a diagram of the Sesame components, which is helpful. Study and memorise!
1) Set up environment: Logging
- Download SLF4J (1.6.6. at time of writing) to get the correct bridge file (slf4j-log4j12-1.6.6.jar) to work with log4j:
- set Java class path to use the log4j bridge jar file: Add the following to the ~/.profile:
(Sesame doc mentions 5.5 or 6.0, so I went with 6.0 instead of 7.0 just to be on the safe side)
- Download binaries from http://tomcat.apache.org/download-60.cgi (version 6.0.35 at the time of writing)
- Then follow instructions on: http://wiki.apache.org/tomcat/TomcatOnMacOS
- I installed it into /Library/Tomcat as recommended by the above post
- Check if Tomcat is running on the default port: http://127.0.0.1:8080
3) Sesame server / workbench installation
- Download Sesame binaries from Download .tar from http://sourceforge.net/projects/sesame/files/Sesame%202/2.6.6/
- Unpack the tar wherever you like
- Deploy war files (in sesame/war directory) using the Tomcat Manager web GUI
>> Workbench is accessible on http://127.0.0.1:8080/openrdf-workbench
Sesame should be up and running now!
The default data directory on Mac OS X is /Users/fishdelish/Library/Application Support/Aduna/OpenRDF Sesame
4a) Create a repository and import RDF data using Sesame console
- start the Sesame console using the shell script provided in the /bin directory
- connect to the server: connect http://localhost:8080/openrdf-sesame.
Create a new store: either in-memory or native. I chose native due to the relatively small RAM on our machines: “The native store uses on-disk indexes to speed up querying.”
In the console, type:
- create native. (then fill in id and description)
- open testfish.
- load /Users/fishdelish/fishbench/testfish.n3.
To exit the console: use exit. or quit.
4a) Create a repository and import RDF data using the Java API
Or do the same using the SesameJava API. Good explanation of the Java API in section 8.2 on http://www.openrdf.org/doc/sesame2/users/ch08.html – I’m just giving you the rough outlines of the code, without error handling etc.
File dataDir = new File("/path/to/datadir/"); Repository myRepository = new SailRepository(new NativeStore(dataDir)); myRepository.initialize();
File file = new File("/path/to/example.rdf"); String baseURI = "http://example.org/example/local"; RepositoryConnection con = myRepository.getConnection(); con.add(file, baseURI, RDFFormat.RDFXML);
5) SPARQL query time!
Connect to repository using the Java API:
String sesameServer = "http://example.org/sesame2"; String repositoryID = "example-db"; Repository myRepository = new HTTPRepository(sesameServer, repositoryID); myRepository.initialize();
Then simply query the Repository() object, as described in the documentation.