Wednesday, November 14, 2007

Creating documents with SPARQL and JSP

My co-workers at TopQuadrant recently had a deadline to create some deliverables for a large customer project (for a national space agency :) ). A large fraction of the work in this project is actually ontology design, and the deliverables were Word documents that described and explained these ontologies. Tired of endless hours of manual work, my manager wished he had a "generate-document-from-ontology" button.

On that same day we implemented a prototypical document generator that allows users to embed SPARQL queries into HTML templates, and then let the system insert the resulting variable bindings into certain spots in the templates. The basic idea is that certain blocks of text (such as a row in an HTML table) are repeated for each result row of the SPARQL query. Furthermore, loops over SPARQL queries can be nested so that you can reference variables from the outside in an inner loop.

This turned out to be a really useful feature, so I generalized this to a new tool feature based on a generic document generation framework, Java Server Pages (JSP). Since I had never implemented anything on top of JSP, I did a quick search on the web, revealing David Powell's SPARQL JSP taglib. This small but fine open-source project turned out to be a very helpful starting point for the implementation of TopBraid Composer's new document generation facility. Since TBC's Maestro Edition comes with its own integrated Java web server, we can now execute Java Server Pages within the development tool.

In a nutshell, this feature can be used to create arbitrary text documents (such as HTML or XML files) from the RDF model that is currently open in Composer. The user selects a JSP page (which can be edited with Eclipse/TBC or tools such as DreamWeaver) and then the output file. The system compiles the JSP page internally into a Servlet and then runs it, writing the result into a new file in the Eclipse workspace. With the TopBraid Live server, these pages can also be put online to produce dynamic web pages.

Here is an example JSP document with embedded SPARQL code. When executed over this ontology, you get this output.


Post a Comment

<< Home