The Spring folks have been putting together an impressive portfolio of data oriented capabilities for NoSQL data stores. To compliment the those capabilities, here is Spring Jena - a project I hope to propose back to the Spring community to provide direct Jena API support and direct SPARQL.
Much like Groovy SPARQL, this is a relatively simple code base that applies the template design pattern to Jena and ARQ to simplify every day needs for creating, modifying, and querying RDF data. There is a lot more work to do here, most noteably the parameterized queries.
Get Spring Jena @ Github here.
The roadmap includes:
- Spring datastore/mapping support for object relational mapping, once those projects reach 1.0
- Spring Transaction support - wrap Jena native transactions or provide app-level transaction management via Spring
- Abstraction for triple stores - likely aligned against the Datastore interface in Spring Data
- QuerySolutionMap overloading to the methods in the SparqlTemplate
- Web / MVC capabilities, such as a taglib
Here is a GIST to get you going:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import org.springframework.data.rdf.sparql.*; | |
import org.springframework.data.rdf.jena.*; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class TestSpringJena { | |
private Model model; | |
private JenaTemplate jena; | |
private SparqlTemplate sparql; | |
@Before | |
public void init() { | |
model = ModelFactory.createDefaultModel(); | |
jena = new JenaTemplate(); | |
sparql = new SparqlTemplate(); | |
jena.setModel(model); | |
sparql.setModel(model); | |
} | |
@Test | |
public void testModel() { | |
jena.add("urn:test", "urn:someProperty", "hello world"); | |
// Select by list | |
String query1 = "SELECT ?x ?y ?z WHERE { ?x ?y ?z }"; | |
List<String> list = sparql.execSelectList(query1, new SolutionMapper<String>() { | |
public String mapSelect(ResultSet rs, int rowNum) { | |
QuerySolution sln = rs.nextSolution(); | |
RDFNode x = sln.get("x"); | |
RDFNode y = sln.get("y"); | |
RDFNode z = sln.get("z"); | |
return x.toString() + "|" + y.toString() + "|" + z.toString(); | |
} }); | |
// result set as a map of strings | |
Map<String, String> map = sparql.execSelectStringMap(query1); | |
// Need one parameter? select a string | |
String query2 = "SELECT ?z WHERE { <urn:test> ?y ?z }"; | |
String result = sparql.execSelectString(query2); | |
} | |
} |
Enjoy!
I have read your blog its very attractive and impressive. I like it your blog.
ReplyDeleteSpring online training Spring online training Spring Hibernate online training Spring Hibernate online training Java online training
spring training in chennai spring hibernate training in chennai