OpenRDF Java client for Blazegraph

February 17, 2015

This is a toy project to play around with Blazegraph's RDF4J client library.

Getting started

Get Blazegraph:

git clone git:// blazegraph

Start Blazegraph:

cd blazegraph
ant start-blazegraph

Running the client

The client code runs as JUnit test(s). Run it with Maven:

$ mvn test


Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.245 s
[INFO] Finished at: 2015-02-19T16:31:23-08:00
[INFO] Final Memory: 20M/218M
[INFO] ------------------------------------------------------------------------


To get a SAIL connection to Blazegraph:

Repository repo = BigdataSailFactory.connect("localhost", 9999);
RepositoryConnection con = LocalConnection.get();


One way to insert a small volume of data is by streaming it in from a file:

FileInputStream fis = new FileInputStream(LocalDump.file());
GZIPInputStream gis = new GZIPInputStream(fis);
con.add(gis, null, RDFFormat.N3);

To insert big volumes of data without blowing the heap, tell Blazegraph to load it:

String query = "LOAD <file://" + LocalDump.path() + ">";
Update update = con.prepareUpdate(QueryLanguage.SPARQL, query);

To perform a SPARQL query:

String queryS =
     "SELECT ?place ?capital WHERE { "
   + "  ?place <> ?capital. "
   + "}";

TupleQuery query = con.prepareTupleQuery(QueryLanguage.SPARQL, queryS);
TupleQueryResult rows = query.evaluate();

And iterate over the resulting rows.