Skip to content
Jim Amsden edited this page Jul 13, 2016 · 6 revisions

Introduction to Apache Jena

Apache Jena includes a number of components;

RDF API - client API for dealing with RDF in Java

Class Model - a collection of RDF triples denoting an RDF (directed) graph. Can be used to adapt existing data sources as RDF. class Graph - a simpler abstraction for wrapping existing data stores

ARQ - Java Application API for SPQRQL queries

TDB - Triple DataBase - used for persisting RDF graphs

Fuseki2 - a SPARQL server integrated with TDB.

Fuseki2 Notes

Here's some notes on experimenting with Fuseki2, installation, startup, and using typical access patterns that would be required by ldp-service.

Start the server

./fuseki-server --update --loc=../mrm /mrm &

Starts the server on the /mrm DatasetPathName using the default port (3030) allowing SPARQL update

Fuseki Dataset Descriptions: --mem Create an empty, in-memory (non-persistent) dataset. --file=FILE Create an empty, in-memory (non-persistent) dataset, then load FILE into it. --loc=DIR Use an existing TDB database. Create an empty one if it does not exist. --desc=assemblerFile Construct a dataset based on the general assembler description. --config=ConfigFile Construct one or more service endpoints based on the configuration description.

Provides these endpoints or dataset URIs:

Command line interface (CLI):

bin/soh VERB datasetURI graphName [file]
  • VERB: post, get, head, put, delete
  • databaseURI is http://localhost:3030/mrm (without data, query, or update)
  • graphName is the URI of the graph or the word default for the default graph
  • file is an RDF file for PUT and POST with the extension used to determine the HTTP content type

Implements the SPARQL 1.1 Graph Store HTTP Protocol

Create a resource (or graph)

bin/soh post http://localhost:3030/mrm  http://example/spc /Users/jamsden/Developer/oslc/spc.ttl

bin/soh post http://localhost:3030/mrm  http://example/spc /Users/jamsden/Developer/oslc/spc.ttl

POST http://localhost:3030/mrm/update?graph=http://example/spc
Content-Type=text/turtle

Read

bin/soh get http://localhost:3030/mrm  http://example/spc

GET http://localhost:3030/mrm/data?graph=http://example/spc
Accept=application/ld+json, text/turtle, application/rdf+xml

Update

bin/soh put http://localhost:3030/mrm  http://example/spc /Users/jamsden/Developer/oslc/spc.ttl

PUT http://localhost:3030/mrm/update?graph=http://example/spc
Content-Type=text/turtle

Or use SPARQL update: s-update --service=endpointURL 'update string' s-update --service=endpointURL --update=updateFile.ru

Delete

bin/soh delete http://localhost:3030/mrm  http://example/spc 

DELETE http://localhost:3030/mrm/update?graph=http://example/spc

Query

s-query --service=endpointURL 'query string'

bin/s-query --service=http://localhost:3030/mrm 'SELECT DISTINCT ?g WHERE {GRAPH ?g {?s ?p ?o }}'
bin/s-query --service=http://localhost:3030/mrm 'SELECT DISTINCT ?s ?p ?o WHERE {GRAPH ?g {?s ?p ?o }}'

Query Using POST Request, you can insert one of the following into the entity request body:

query=SELECT+%2A+%7B%3Fs+%3Fp+%3Fo%7D query=SELECT * {?s ?p ?o}

The Header needs to be customized to have Content-Type = application/x-www-form-urlencoded. The URL would be http://localhost:3030/mrm/query

I found this information when looking at one of the 's-' code. There is a method called cmd_sparql_query (line 497) that shows all types of options when calling s-query. There is an option called --post that forces the request to be a POST rather than a GET like usual. I implemented the POST and the header output was as follows:

SPARQL http://localhost:3030/ds/query
POST http://localhost:3030/ds/query
  User-Agent:          SOH/Fuseki 1.0.0
  Accept:              application/sparql-results+json , application/sparql-results+xml;q=0.9 , text/turtle;charset=utf-8 , application/n-triples;q=0.9 , application/rdf+xml;q=0.8 , application/ld+json;q=0.5 , */*;q=0.1
  Content-Type:        application/x-www-form-urlencoded
  Content-Length:      37
200 OK
  Date:                Fri, 27 May 2016 20:16:49 GMT
  Fuseki-Request-Id:   10
  Cache-Control:       must-revalidate,no-cache,no-store
  Pragma:              no-cache`
  Content-Type:        application/sparql-results+json; charset=utf-8
Transfer-Encoding:   chunked

Fuseki also supports Content-Type=application/sparql-query

POST http://localhost:3030/mrm/query
Content-Type=application/sparql-query
SELECT * 
WHERE {GRAPH 
  {?s ?p ?o}
}