Loading Data Into Jena SDB
The
example RDF model from the previous article
Why Migrate to the Semantic Web can be loaded in SDB using the command:
SDBROOT > bin/sdbload --sdb=sdb.ttl http://www.3kbo.com/examples/building.rdf
The SDB Commands provide a number of ways to check whether the data loaded correctly.
A generic test is to run the sdbdump command, which lists all the RDF triples loaded:
SDBROOT > bin/sdbdump --sdb=sdb.ttl
Use the
sdbquery command to make SPARQL queries. For example, the following lists the
RDF triples in simple table form:
SDBROOT > bin/sdbquery --sdb=sdb.ttl 'SELECT ?s ?p ?o WHERE {?s ?p ?o }'
This command writes out the model in N3 format:
SDBROOT > bin/sdbquery --sdb=sdb.ttl 'CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o }'
You can list all people in the model with the query:
SDBROOT > bin/sdbquery --sdb=sdb.ttl 'CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o . ?s a
<http://xmlns.com/foaf/0.1/Person>}'
Details of the BreakerBay building project are provided with the query:
SDBROOT > bin/sdbquery --sdb=sdb.ttl 'CONSTRUCT {<http://3kbo.com/examples/building.rdf#BreakerBay> ?p ?o}
WHERE {<http://3kbo.com/examples/building.rdf#BreakerBay> ?p ?o }'
This gives the result:
:BreakerBay
rdf:type :BuildingProject ;
rdfs:comment "House extension and landscaping" ;
rdfs:label "Breaker Bay "^^xsd:string ;
:approvedBy :WellingtonCityCouncil ;
:builtBy :GarethEvans ;
:designedBy :AlexGreig ;
foaf:based_near <http://dbpedia.org/resource/Wellington> ;
foaf:fundedBy :RichardHancock .
Creating a Maven-based Web Application
Use
Maven to manage the dependencies between the various component libraries required by the application. Download and install it from the Maven site if it is not installed already.
Running the following maven command creates the initial project structure of a maven based web app application,
creating a top level directory named "sdb-joseki".
mvn archetype:create -DgroupId=com.devx -DartifactId=sdb-joseki -DarchetypeArtifactId=maven-archetype-webapp
| Author's Note: If you are new to Maven check out the instructions for
Building a Project with Maven. |
Download and unzip Joseki and copy the contents of the
Joseki-3.2/webapps/joseki directory to the
sdb-joseki/src/main/webapp directory as shown in
Figure 1.
 |
|
|
Figure 1. Project Structure: Copy the contents of the directory. |
From the source code, add the provided
joseki-config.ttl and
log4j.xml files to the
src/main/resources directory and replace the generated
pom.xml with the one provided.
The joseki-config.ttl file configures Joseki to work with the RDF data loaded into SDB.
(Change the username and password in the joseki-config.ttl file to match that used for the
MySQL "sdb" database.)
In the WEB-INF/web.xml file, comment out the servlet-mapping for books url-pattern because only the default
graph was configured in joseki-config.ttl file.
<!-- Demo service
<servlet-mapping>
<servlet-name>SPARQL service processor</servlet-name>
<url-pattern>/books</url-pattern>
</servlet-mapping>
-->
The provided
pom.xml file contains all the dependencies needed to build the
sdb-joseki.war file,
however
joseki.jar is not available from an external maven repository.
On the command line, change into the directory Joseki-3.2/lib and add joseki.jar to the local maven
repository by running the command:
mvn install:install-file -DgroupId=org.joseki -DartifactId=joseki -Dversion=3.2 -Dpackaging=jar -Dfile=joseki.jar
Change into the directory
sdb-joseki. The
sdb-joseki.war file can now be built by
running the command:
mvn package
Deploy the
sdb-joseki.war file to Tomcat to provide a SPARQL endpoint querying the default
graph, i.e., the data loaded into SDB. Test that the SPARQL endpoint is working by opening the form at
http://localhost:8080/sdb-joseki/sparql.html and submitting the query
'
CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o }'.
In Firefox, with the Tabulator Extension installed, the default graph is displayed as per
Figure 2.
Another query to try is "
CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o . ?s a <http://xmlns.com/foaf/0.1/Person>}", which
results in Figure 3.

Figure 2. Default Graph: How the default graph appears with the Tabulater Extension installed. |
|

Figure 3. Listing Of People: A certain query provides a listing of people. |
At this point, you have laid the foundation of a semantic web application and you have created a maven web application
project that implements an RDB triple store using Jena SDB and a SPARQL endpoint via Joseki. The next article in this
series will discuss adding the Spring Security and JAX-RS to enable the publication of public and private Linked Data.