Skip to content

0607060123/jena-sparql-api

 
 

Repository files navigation

Welcome to the Jena SPARQL API project!

Build Status

This library offers several Jena-compatible ways to transparently add delays, caching, pagination, retry and even query transformations before sending off your original SPARQL query. This frees your application layer from the hassle of dealing with those issues. Also, the server module bundles Jena with the Atmosphere framework, giving you a kickstart for REST and websocket implementations.

Maven

<repositories>
	<repository>
	    <id>maven.aksw.internal</id>
	    <name>University Leipzig, AKSW Maven2 Repository</name>
	    <url>http://maven.aksw.org/archiva/repository/internal</url>
	</repository>
	
	<repository>
	    <id>maven.aksw.snapshots</id>
	    <name>University Leipzig, AKSW Maven2 Repository</name>
	    <url>http://maven.aksw.org/archiva/repository/snapshots</url>
	</repository>
</repositories>

<dependencies>
	<dependency>
		<groupId>org.aksw.jena-sparql-api</groupId>
		<artifactId>jena-sparql-api-core</artifactId>
		<version>2.12.1-8</version>
	</dependency>
	
	<dependency>
		<groupId>org.aksw.jena-sparql-api</groupId>
		<artifactId>jena-sparql-api-server</artifactId>
		<version>2.12.1-8</version>
	</dependency>
	
	...
</dependencies>

Project structure

This library is composed of the following modules:

  • jena-sparql-api-core: Contains the core interfaces and basic implementations.
  • jena-sparql-api-server: An abstract SPARQL enpdoint class that allows you to easily create your own SPARQL endpoint. For example, the SPARQL-SQL rewriter Sparqlify is implemented against these interfaces.
  • jena-sparql-api-utils: Utilities common to all packages.
  • jena-sparql-api-example-proxy: An example how to create a simple SPARQL proxy. You can easily adapt it to add pagination, caching and delays.

Usage

Here is a brief summary of what you can do. A complete example is avaible here.

Http Query Execution Factory

QueryExecutionFactory qef = new QueryExecutionFactoryHttp("http://dbpedia.org/sparql", "http://dbpedia.org");

Adding a 2000 millisecond delay in order to be nice to the backend

qef = new QueryExecutionFactoryDelay(qef, 2000);

Set up a cache

// Some boilerplace code which may get simpler soon
long timeToLive = 24l * 60l * 60l * 1000l; 
CacheCoreEx cacheBackend = CacheCoreH2.create("sparql", timeToLive, true);
CacheEx cacheFrontend = new CacheExImpl(cacheBackend);

qef = new QueryExecutionFactoryCacheEx(qef, cacheFrontend);

Add pagination with (for the sake of demonstration) 900 entries per page (we could have used 1000 as well). Note: Should the pagination abort, such as because you ran out of memory and need to adjust your settings, you can resume from cache!

qef = new QueryExecutionFactoryPaginated(qef, 900);

Create and run a query on this fully buffed QueryExecutionFactory

String queryString = "SELECT ?s { ?s a <http://dbpedia.org/ontology/City> } LIMIT 5000";
QueryExecution qe = qef.createQueryExecution(queryString);
		
ResultSet rs = qe.execSelect();
System.out.println(ResultSetFormatter.asText(rs));

Proxy Server Example

This example demonstrates how you can create your own SPARQL web service. You only have to subclass SparqlEndpointBase and override the createQueryExecution method. Look at the Source Code to see how easy it is.

Running the example:

cd jena-sparql-api-example-proxy
mvn jetty:run
# This will now start the proxy on part 5522

In your browser or a terminal visit:

http://localhost:5522/sparql?service-uri=http://dbpedia.org/sparql&query=Select * { ?s ?p ?o } Limit 10

License

The source code of this repo is published under the Apache License Version 2.0.

This project makes use of several dependencies: When in doubt, please cross-check with the respective projects:

About

A collection of Jena-extensions for hiding SPARQL-complexity from the application layer

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%