RDF with Jena and Fuseki (Part 3 of 3): Query RDF data in Jena and Fuseki

See Part 2: Validate and store RDF data in Jena and Fuseki

Keep these in mind

W3C SPARQL Query Language

SPARQL over HTTP

Get Started

Assuming we have a running Fuseki server and a modest dataset from Part 2, visit your Fuseki control panel (http://localhost:3030/control-panel.tpl), select the dataset, and post a query. This simple query selects all triples from the dataset as subject, predicate, object.

SELECT * {?s ?p ?o}

Run the same query using the SPARQL-over-HTTP command-line tools that come with Fuseki:

$ cd [path_to_fuseki]/jena-fuseki-1.0.0
 $ ./s-query --service http://localhost:3030/ds/query 'SELECT * {?s ?p ?o}'

Back in the Fuseki control panel select all linkedAuthor and linkedInformationResource:

PREFIX core: <http://vivoweb.org/ontology/core#>
PREFIX bibo: <http://purl.org/ontology/bibo/>
SELECT ?author ?work
WHERE
{
?x core:linkedAuthor ?author.
?x core:linkedInformationResource ?work
}

Gist at Github

…and using s-query:

$ ./s-query --service http://localhost:3030/ds/query 'PREFIX core: <http://vivoweb.org/ontology/core#> PREFIX bibo: <http://purl.org/ontology/bibo/>SELECT ?author ?work WHERE { ?x core:linkedAuthor ?author. ?x core:linkedInformationResource ?work }'
RDF with Jena and Fuseki (Part 3 of 3): Query RDF data in Jena and Fuseki

RDF with Jena and Fuseki (Part 2 of 3): Validate and Store RDF data in Jena and Fuseki

See Part 1: Installing Fuseki (with TDB) server and Jena command-line tools on OS X.

Keep these in mind

Reading and writing RDF in Jena

Get Started

I hear the WWW may have some data about published research:

$ cd jena-fuseki-1.0.0
$ curl -o ./Data/bibapp_works.rdf 'http://experts.kumc.edu/search?utf8=%E2%9C%93&q=mass+spectrometry&commit=Search&format=rdf'

It’s supposed to be RDF/XML. Let’s validate that using Jena’s CLI. Fuseki’s web UI has a validator, but it doesn’t support RDF/XML:

$ rdfxml --validate ./Data/bibapp_works.rdf

We’re getting to the fun part. Let’s push some RDF into a Fuseki dataset.

Normally, we should be able to use the SPARQL HTTP support with s-put. With our TDB datastore:

$ ./s-put -v http://localhost:3030/ds/data default ./Data/bibapp_works.rdf

With the in-memory datastore, I kept getting NoMethod on ‘nil’ from Ruby. I suspect it has to do with a content-type or encoding declaration. If you run into the same problem, try using PUT with curl instead of s-put like this:

$curl -X PUT -H "Content-Type: application/rdf+xml" -d ./Data/bibapp_works.rdf http://localhost:3030/ds/data?default

Did it work? Retrieve the entire dataset serialized to RDF and paired with the graph IRI.

$ ./s-get http://localhost:3030/ds/data default

See Part 3: Query RDF data in Jena and Fuseki

RDF with Jena and Fuseki (Part 2 of 3): Validate and Store RDF data in Jena and Fuseki

RDF with Jena and Fuseki (Part 1 of 3): Installing Fuseki (with TDB) server and Jena command-line tools on OS X

Fuse-what?

This begins a 3-part series on learning to use Jena and Fuseki for parsing, validating, and querying RDF. This series grew out of the Linked Data Toolshare workshop, Code4Lib Midwest 2013, that I facilitated with Shawn Averkamp.

Apache Jena provides a Java framework and command-line tools for working with Linked Data. Fuseki is a SPARQL server that provides HTTP endpoints to your RDF data.  Together, they provide a rich and convenient toolset for building Semantic Web applications.

I assume you already have some RDF data. If not, no worries; I provide a source.

Keep these in mind

Jena command-line tools We don’t need the Jena CL tools for running Fuseki, but they include some scripts for validating our data. Specifically, Fuseki doesn’t include a validator for RDF/XML.

Getting Started with Fuseki

Apache Jena binaries downloads

Get Started

Download and extract the Jena binary:

$ curl -O http://www.apache.org/dist/jena/binaries/apache-jena-2.11.0.tar.gz
$ tar xvfz apache-jena*.gz

Set environment variables for Jena command-line tools:

$ export JENAROOT=[/path_to_apache-jena-2.11.0]
$ export PATH=$PATH:$JENAROOT/bin

Verify:

$ sparql --version

Download and extract the Fuseki binary:

$ curl -O http://www.apache.org/dist/jena/binaries/jena-fuseki-1.0.0-distribution.tar.gz
$ tar xvfz jena-fuseki*.gz

Make fuseki-server executable:

$ cd jena-fuseki-1.0.0
$ chmod +x fuseki-server s-*

Start fuseki-server. The options below starts fuseki-server with an in-memory, non-persistent datastore. It gets flushed when you stop the server. The –update option allows us to write to the datastore.

$ ./fuseki-server --update --mem /ds

A temporary datastore might come in handy some day, but since Fuseki comes with TDB built-in, let’s create a persistent datastore. You can pre-configure your TDB datastore to meet your needs, but we’re just going to take the basic included configuration. First, create a new directory ./DB to hold your datastores.

$ mkdir ./DB
$ ./fuseki-server --update --loc=DB /ds

See Part 2: Validate and Store RDF data in Jena and Fuseki

RDF with Jena and Fuseki (Part 1 of 3): Installing Fuseki (with TDB) server and Jena command-line tools on OS X