Transcript Jena

Jena
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.
Introduction
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.
Architecture
Jena Interfaces and Pluggable
API
Here we plug in a RFDa reader that allows
Jena to parse the extracted RDF into a
model.
This works as it conforms to a Jena
interface and hence extends
theramework.
https://github.com/shellac/java-rdfa
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
RDF/XML
RDF/XML-ABBREV
N-TRIPLE
N3 - Notation3
TTL or Turtle
•
•
•
•
•
Parsers and Writers example
http://www.w3.org/2001/sw/grddl-wg/td/hCardFabien-RDFa.html
Parsers and Writers example
Here we read an RDFa document
and write out in N3 notation.
RDF API
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
model.
RDF API - continued
Ontologies
Supported in Jena -
•
•
•
•
•
•
•
Transitive
DAML + OIL
RDFS
General Rule Based
OWL Full(Limits) (only as an
external)
OWL Lite (partially implemented)
OWL Micro (one of the partial
implementations)
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
reasoner:
Model schema = FileManager.get().loadModel("file:data/rdfsDemoSchema.rdf");
Model data = FileManager.get().loadModel("file:data/rdfsDemoData.rdf");
InfModel infmodel = ModelFactory.createRDFSModel(schema, data);
http://openjena.org/inference/#rdfs
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);
http://openjena.org/inference/#owl
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: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <http://dig.csail.mit.edu/2010/LinkedData/testdata/family#>
.
: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:
<http://dig.csail.mit.edu/2010/LinkedData/testdata/family#> .
@prefix :
<http://dig.csail.mit.edu/2010/LinkedData/testdata/family_data#> .
: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 API
SPARQL implementation in Jena resembles
a striking similarity with that of the JDBC
API.
Fuseki
A REST style SPARQL web service. SPARQL
1.1 queries can be called over the HTTP
protocol.
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
database.
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
http://www.ibm.com/developerworks/xml/library/j-jena/
Protégé
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.
JenaBean
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
entity.
• You must specify the type of each primitive
value.
• Properties must be created for each bean
property.
JenaBean
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
JenaBean
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.
D2RQ
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
RDF.
D2RQ overview
• Mapping files are
•
read by the D2RQ
engine that converts
relational database
data into RDF
format.
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.