a introduction
Semantic Web Tools
Jena - Background
Originally devised by HP Labs in Bristol, it
was developed by Brian McBride of
Hewlett-Packard and was derived from
the SiRPAC API which offered only a
command line interface. The framework
is open-source and is offered under the
BSD license.
Jena is built on java and gives the semantic
web developers an assortment of tools at
his or her disposal.
Vast use of interfaces allow developers to
extend Jena’s functionality by using the
plugin interface.
Jena Interfaces and Pluggable
Here we plug in a RFDa reader that allows
Jena to parse the extracted RDF into a
This works as it conforms to a Jena
interface and hence extends
Parsers and Writers
We have just shown how to extend a parser
to create a model. Here we can read and
write to an stream via
N3 - Notation3
TTL or Turtle
Parsers and Writers example
Parsers and Writers example
Here we read an RDFa document
and write out in N3 notation.
Jena manipulates RDF data in directed
graph structures also called models. The
RDF API is extendable to include
reasoners to allow for inference of
extended RDF data in a newly created
RDF API - continued
Supported in Jena -
General Rule Based
OWL Full(Limits) (only as an
OWL Lite (partially implemented)
OWL Micro (one of the partial
Ontology Api: Creating RDFS
inference model
The following code shows loading some
data and a schema from disk then how
simple it is to create an inference model
in Jena that could be interrogated by a
Model schema = FileManager.get().loadModel("file:data/rdfsDemoSchema.rdf");
Model data = FileManager.get().loadModel("file:data/rdfsDemoData.rdf");
InfModel infmodel = ModelFactory.createRDFSModel(schema, data);
Ontology Api: Creating an OWL
inference model
Model schema = FileManager.get().loadModel("file:data/owlDemoSchema.owl");
Model data = FileManager.get().loadModel("file:data/owlDemoData.rdf");
Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
reasoner = reasoner.bindSchema(schema);
InfModel infmodel = ModelFactory.createInfModel(reasoner, data);
Where an RDFS inference model only
requires the schema and data an OWL
inference model needs a reasoner which in
turn uses the OWL schema.
Ontology API (RDFS - schema)
@prefix rdfs: <> .
@prefix rdf: <> .
@prefix : <>
:Mammal rdf:type rdfs:Class.
:Person rdfs:subClassOf :Mammal.
:Male rdfs:subClassOf :Person.
:Female rdfs:subClassOf :Person.
:parent rdf:type rdf:Property.
:mother rdfs:subPropertyOf :parent;
rdfs:range :Female;
rdfs:domain :Person.
Ontology API (RDF data)
@prefix fam:
<> .
@prefix :
<> .
:Mary a fam:Mammal .
:Mary a fam:Female .
:Frank a fam:Male .
Ontology API
Below we look at build an inferred RDFS
model and show the results specific to
our inference about the resource 'Male'
Inference API - Reasoners
Jena allows pluggable or standard reasoners
to extend its graph of connected resources
or models.
Using the reasoners, additional RDF data is
added to give return an inferred model.
SPARQL implementation in Jena resembles
a striking similarity with that of the JDBC
A REST style SPARQL web service. SPARQL
1.1 queries can be called over the HTTP
Uses lightweight Jetty as a Web Servlet
container. There are plans to create a
war archive to allow other servlet
engines to be able to host Fuseki.
Store API
TDB - a ACID compliant dedicated triple
store written in Java that includes an
inbuilt query optimiser.
Memory - a volatile store.
SDB - an adapter library that allows for RDF
data to be persisted to a conventional
relational database.
Custom - custom implementations can be
created to store triples such as text files or
some other binary format.
Querying a Database
Querying a database in Jena is very similar
to querying a regular relational database in
java, we need a database connection with
which to run queries and update the
Due to the modular design of Java we are
free to use whatever connector that will
suit our data source
Querying a persistent store
Some sample code using the MySQL JDBC
database connector to build a model from
an MySQL relational database
Protégé-OWL has always had a close
relationship with Jena.
The Jena ARP parser is still used in the
Protégé-OWL parser, and various other
services such as species validation and
data type handling have been reused
from Jena.
A library which aims to simplify the process
of creating rdf data. Jenabean attempts
to resolve the following Jena pain points
• You need to create unique URI’s for every
• You must specify the type of each primitive
• Properties must be created for each bean
Three annotations to help describe RDF
data from Java Beans.
• @Id specifies unique field
• @Namespace provides a domain
• @RdfProperty maps java properties to
RDF properties
Bean2RDF or RDF2Bean can be used to
parse and write. These are wrapper
classes around the Jena library.
By annotating objects/beans data can be
retrieved from any source and have RDF
data added. This allows for flexibility
when using in conjunction with legacy
data stores.
Provides access to relational databases as
RDF graphs. This allows users to publish
linked data to the web and has the ability
to be queried via SPARQL.
D2RQ includes a mapping interface to help
convert/translate relational data into
D2RQ overview
• Mapping files are
read by the D2RQ
engine that converts
relational database
data into RDF
D2R server then
provides an interface
for presenting or
querying of data.
Jena Summary
Provides a fine framework for creating
semantic web applications. It serves as a
base to allow for other libraries extend its
capabilities allowing developers to keep
up with changes of the various protocols.
In order to fully utilise Jena in a web app
we can use tools such as Protege to design
schema's for inference and then have this
stored for use with Jena's Ontology.