https://github.com/smartdataanalytics/jena-sparql-api
A collection of Jena-extensions for hiding SPARQL-complexity from the application layer
https://github.com/smartdataanalytics/jena-sparql-api
Last synced: 5 months ago
JSON representation
A collection of Jena-extensions for hiding SPARQL-complexity from the application layer
- Host: GitHub
- URL: https://github.com/smartdataanalytics/jena-sparql-api
- Owner: SmartDataAnalytics
- License: other
- Created: 2013-03-30T20:46:44.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2022-12-10T06:14:59.000Z (over 2 years ago)
- Last Synced: 2024-05-15T12:29:57.297Z (12 months ago)
- Language: Java
- Homepage:
- Size: 32.6 MB
- Stars: 56
- Watchers: 20
- Forks: 14
- Open Issues: 27
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Welcome to the Jena SPARQL API project
An advanced Jena-based SPARQL processing stack for building Semantic Web applications.Highlights:
* Fluent SPARQL Query API - Transparently enhance query execution with caching, pagination, rewriting, transformations, and so on, without having to worry about that in your application logic.
* Transparent basic (normalized) string caching - Just the usual string based caching as it has been implemented over and over again
* Query Transformations
* SPARQL sub graph isomorphism checker
* Transparent sub graph isomorphy cache - Uses the isomorphism checker for caching - Detects whether prior result sets fit into a current query - regardless of variable naming.
* JPA-based Java<->RDF mapper: Run JPA criteria queries over Java classes which are actually backed by SPARQL.[](http://ci.aksw.org/jenkins/job/jena-sparql-api/)
This library offers several [Jena](http://jena.apache.org/)-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](https://github.com/Atmosphere/atmosphere) framework, giving you a kickstart for REST and websocket implementations.
### Maven
Releases are available on [maven central](http://search.maven.org/#search%7Cga%7C1%7Cjena-sparql-api).
Snapshots are presently published in our own archiva:```xml
maven.aksw.snapshots
University Leipzig, AKSW Maven2 Repository
http://maven.aksw.org/archiva/repository/snapshots
org.aksw.jena-sparql-api
jena-sparql-api-core
{check available versions with the link below}
...```
Latest version(s): [jena-sparql-api on maven central](http://search.maven.org/#search%7Cga%7C1%7Cjena-sparql-api)
### 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](http://github.com/AKSW/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.
* `jena-sparql-api-sparql-ext`: SPARQL extensions for processing non-RDF data as part of query evaluation. Most prominently features support for querying JSON documents and unnesting JSON arrays to triples. (We should also add CSV processing for completeness, although covered by the TARQL tool).
* `jena-sparql-api-jgrapht`: Provides a JGraphT wrapper for Jena's Graph interface. Yes, we were aware that RDF is not a plain graph, but a labeled directed pseudo graph and implemented it accordingly. Also contains conversions of SPARQL queries to graphs. Enables e.g. subgraph isomorphism analysis.
* `jena-sparql-api-mapper`: Powerful module to query RDF data transparently with the Java Persistence API (JPA) criteria queries. I.e. queries and updates are expressed over (annotated) Java classes, and no RDF specifics are exposed to the developer.### Usage
Here is a brief summary of what you can do. A complete example is avaible [here](https://github.com/AKSW/jena-sparql-api/blob/master/jena-sparql-api-core/src/main/java/org/aksw/jena_sparql_api/example/Example.java).
Http Query Execution Factory
```Java
QueryExecutionFactory qef = new QueryExecutionFactoryHttp("http://dbpedia.org/sparql", "http://dbpedia.org");
```
Adding a 2000 millisecond delay in order to be nice to the backend
```Java
qef = new QueryExecutionFactoryDelay(qef, 2000);
```
Set up a cache```Java
// 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!
```Java
qef = new QueryExecutionFactoryPaginated(qef, 900);
```
Create and run a query on this fully buffed QueryExecutionFactory
```Java
String queryString = "SELECT ?s { ?s a } 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](https://github.com/AKSW/jena-sparql-api/blob/master/jena-sparql-api-example-proxy/src/main/java/org/aksw/jena_sparql_api/example/proxy/SparqlEndpointProxy.java) to see how easy it is.Running the example:
```bash
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](http://localhost:5522/sparql?service-uri=http%3A%2F%2Fdbpedia.org%2Fsparql&query=Select%20%2A%20%7B%20%3Fs%20%3Fp%20%3Fo%20%7D%20Limit%2010)
## License
The source code of this repo is published under the [Apache License Version 2.0](https://github.com/AKSW/jena-sparql-api/blob/master/LICENSE).This project makes use of several dependencies: When in doubt, please cross-check with the respective projects:
* [Apache Jena](https://jena.apache.org/) (Apache License 2.0)
* [Atmosphere](https://github.com/Atmosphere/atmosphere) (Apache License 2.0/Partially CDDL License)
* [Guava](http://code.google.com/p/guava-libraries/) (Apache License 2.0)
* [commons-lang](http://commons.apache.org/proper/commons-lang/) (Apache License 2.0)
* [rdf-json-writer](https://github.com/kasabi/rdf-json-writer) (currently copied but also under Apache 2.0 license, will be changed to maven dep)