Saturday, July 30, 2011

Linked Data Microframework: Linked Ratpack

The other day I ran across some of the Sinatra inspired web microframeworks available in various languages, including Ratpack for Groovy.  Given RDF builder DSL in Groovy Sparql, I thought it would be a nice thought expertiment to create a microframework for linked data and RDF.  After an afternoon of coding and testing, the results look quite promising.  So here it is - Linked Ratpack, a microframework for Linked Data.

Linked RP works the same way Ratpack does - you provide a single Domain Specific Language (DSL) script where you write your methods to perform some function on a URL, and it weaves those in to a Jetty container.  In this case, I've added some capabilities to Ratpack to work with linked data:

  • RDFBuilder from Groovy SPARQL is automatically available to the DSL script under the 'rdf' variable
  • link(String endpoint) is available as a function to get an instance of the Groovy SPARQL Sparql class for performing Sparql queries.
  • resolve(String uri) is a new piece of functionality that uses Groovy's HTTPBuilder DSL and Jena to retrieve a URL and read it into RDF.  It should work across various RDF serialization types, and likely bomb out on HTML or anything else if you feed it an incorrect URI
The following Gist illustrates everything fairly nicely:

You can now browse to the following URLs:
  • localhost:4999/
  • localhost:4999/tim
  • localhost:4999/groovy

Note: since Jena models being returned by those functions get automatically serialized back out - if you want to do serialization inline - return null

To get started with Linked Ratpack, you must do the following:
  1. Get Groovy SPARQL from Github, and build/install it with Gradle
  2. Get Linked Ratpack from Github, and build it
  3. Create simple groovy scripts, like the above gist, and run "ratpack path/to/whatever.groovy"
This will start an HTTP server on whatever port you define in the DSL.  After that, you can start browsing to your URLs, hooking up SPARQL endpoint and generating RDF.

For me, this is one of the missing pieces in building linked data applications - an easy way to stand up little RDF servers to test walking RDF graphs hop-by-hop and perform URI de-referencing, and experimenting with generating derivative RDF sites from other RDF data sources (e.g. SPARQL Construct).

Many thanks to Justin Voss ( @ github ) for creating Ratpack in the first place, it was a solid foundation to build off of.


Wednesday, July 13, 2011

Groovy SPARQL 0.2 Available

Version 0.2 of Groovy SPARQL is now available.  This minor release includes a Groovy DSL for RDF, now you can build RDF and then query it.  The Groovy DSL is fairly flexible and takes advantage of a number of Groovy features including:
  1. Optional syntax in Groovy 1.8 for more fluid DSLs
  2. GPars, aka the Groovy Parallelizer for asynchronous output hooks
  3. Usage of the BuilderSupport class
 Per previous posts on the blog, if you want to use it in Grails / GroovyConsole / other apps, I recommend downloading, doing the Gradle build, install into your local Maven repo and then you can include it easily enough in whatever build environment you are using.

Here is a GIST showing the RDFBuilder DSL in action, with comments noting all of the 'features' available so far.  This is still a work in progress, and the more I attempt to use it to build FOAF and other vocabularies, I'm sure I'll be shaking some bugs out (not the least of which is the wonderful world of URI fragments).


Thursday, July 7, 2011

Gradle, Maven, and Grapes Working Together

For Groovy SPARQL and Spring Jena, I wanted to start leveraging these in little test Groovy scripts running in the console or command line.  At first, I assumed the maven install that happens in their Gradle builds would immediately be picked up by Grape.  However, Grape uses Ant+Ivy, and Ivy does not look in your maven repo by default (doesn't it seem like it should?).

So here are the missing pieces of the puzzle:
  1. Setup your Gradle build to create a POM and install your jars into your local maven repo
  2. Add  Maven repo support to your Grape configuration.  Grape configuration is in ~/.groovy/grapeConfig.xml - and it's an Ivy file in disguise.  See [*] below for an example which is down near the bottom of the Grape documentation.
  3. Install your POM artifacts into Grape.  For Groovy SPARQL, the command is:    grape install org.codehaus.groovy.sparql groovy-sparql 0.1
  4. Now you can use Grape, e.g. @Grab('org.codehaus.groovy.sparql:groovy-sparql:0.1')

You can also use grape list to see what jars are now available.

All in all, this makes tools like the Groovy Console an excellent REPL for both Java, Groovy, and presumably other Java polyglot programming.

     * Here is the sample grapeConfig.xml file from the Groovy documentation.

    Tuesday, July 5, 2011

    Announcing Spring Jena

    On the heels of Groovy SPARQL, here is an initial code base for standard Java and Spring applications -- Spring Jena!

    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: