Skip to content. | Skip to navigation

Personal tools

Navigation

You are here: Home / Members / jhb / Getting started with Jena, Fuseki and OWL Reasoning

Getting started with Jena, Fuseki and OWL Reasoning

by Jörg Baach last modified Jul 23, 2015 03:19 PM
I want to research some RDF features. How do I setup a fuseki server with owl reasoning?

I managed to get to get jena fuseki running with owl reasoning, for in memory databases and for a tdb database (jenas own persistance mechansim). For sdb I am still working on getting the owl reasoner to work (hints appreciated), but at least the service works as such.

Setup

First, lets do the basic setup. I have an mysql server and sun java installed.

#base directory
mkdir fuseki
cd fuseki

#for the libraries
mkdir lib

#for the tdb data
mkdir DB

#the distributed sdb only works with 0.2.4
wget -O jena-fuseki-0.2.4-distribution.tar.gz "http://search.maven.org/remotecontent?filepath=org/apache/jena/jena-fuseki/0.2.4/jena-fuseki-0.2.4-distribution.tar.gz"
tar xf jena-fuseki-0.2.4-distribution.tar.gz
cp jena-fuseki-0.2.4/fuseki-server.jar .
cp -R jena-fuseki-0.2.4/pages .
rm -R jena-fuseki-0.2.4*

#the libraries
cd lib
wget -O jena-sdb-1.3.5.jar "http://search.maven.org/remotecontent?filepath=org/apache/jena/jena-sdb/1.3.5/jena-sdb-1.3.5.jar"
wget -O mysql-connector-java-5.1.22.jar "http://search.maven.org/remotecontent?filepath=mysql/mysql-connector-java/5.1.22/mysql-connector-java-5.1.22.jar"
cd ..

Now, download the fuseki.sql file into the fuseki directory that we created, and lets do the database configuration:


mysql -u <dbroot> -p<dbpassword> -e 'create database fuseki; grant all on fuseki.* to fuseki@localhost'
mysql -u fuseki fuseki < fuseki.sql

(This is a shortcut version, a longer description is at http://ankitjain.info/ankit/2009/06/21/configure-jena-sdb-mysql-ubuntu/)

Configuration

Here is the contents of my configuration file. It configures three services:

  • memory - this is the in memory database, which is not persistent
  • tdb - which saves the data into the DB directory we created earlier on
  • mysql - which uses mysql for storing the data (but can't do the owl reasoning yet, working on it)

Save it (or download it) as config.ttl:

fds@prefix :        <#> .
@prefix fuseki:  <http://jena.apache.org/fuseki#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
@prefix tdb:     <http://jena.hpl.hp.com/2008/tdb#> .
@prefix ja:      <http://jena.hpl.hp.com/2005/11/Assembler#> .
@prefix sdb: <http://jena.hpl.hp.com/2007/sdb#> .

[] rdf:type fuseki:Server ;

fuseki:services (
<#memory>
<#tdb>
<#mysql>
) .

# Custom code.
[] ja:loadClass "com.hp.hpl.jena.tdb.TDB" .
[] ja:loadClass "com.hp.hpl.jena.sdb.SDB" .


########################################################################
#In Memory    

<#memory>  rdf:type fuseki:Service ;
fuseki:name              "memory" ;             # http://host/inf
fuseki:serviceQuery      "sparql" ;          # SPARQL query service
fuseki:serviceUpdate     "update" ;
fuseki:dataset           <#dataset1> ;       #select which set to
.                                            #use




<#dataset1> rdf:type       ja:RDFDataset ;
ja:defaultGraph       <#model_inf_1> ;
.

<#model_inf_1> rdfs:label "Inf-1" ;
ja:reasoner
[ ja:reasonerURL
<http://jena.hpl.hp.com/2003/OWLFBRuleReasoner>];
.

########################################################################
# TDB
<#tdb>  rdf:type fuseki:Service ;
fuseki:name              "tdb" ;             # http://host/inf
fuseki:serviceQuery      "sparql" ;          # SPARQL query service
fuseki:serviceUpdate     "update" ;
fuseki:dataset           <#dataset2> ;       #select which set to
.                                            #use
tdb:GraphTDB    rdfs:subClassOf  ja:Model .

<#dataset2> rdf:type ja:RDFDataset ;
ja:defaultGraph <#model2>;
.         

<#model2> a ja:InfModel;
ja:baseModel <#tdbGraph>;
ja:reasoner
[ ja:reasonerURL
<http://jena.hpl.hp.com/2003/OWLFBRuleReasoner>];
.
<#tdbGraph> rdf:type tdb:GraphTDB;
tdb:location "DB";
.

########################################################################
#SDB / Mysql - doesn't work with owl yet

<#mysql>  rdf:type fuseki:Service ;
fuseki:name              "mysql" ;             # http://host/inf
fuseki:serviceQuery      "sparql" ;          # SPARQL query service
fuseki:serviceUpdate     "update" ;
fuseki:dataset           <#dataset2> ;       #select which set to
.                                            #use


sdb:DatasetStore rdfs:subClassOf ja:RDFDataset .
<#dataset3>  rdf:type sdb:DatasetStore ;
ja:defaultGraph       <#model3> ;
sdb:store <#store>;
.

<#model3> a ja:InfModel;
ja:baseModel <#sdbGraph>;
ja:reasoner
[ ja:reasonerURL
<http://jena.hpl.hp.com/2003/OWLFBRuleReasoner>];
.

<#sdbGraph> rdf:type ja:Model;
.

<#store> rdf:type sdb:Store  ;
rdfs:label "SDB" ;
sdb:layout "layout2" ;
sdb:engine "InnoDB" ;
sdb:connection
[  rdf:type sdb:SDBConnection ;
sdb:sdbType "MySQL" ;
sdb:sdbHost "localhost" ;
sdb:sdbName "fuseki";
sdb:sdbUser "fuseki";
sdb:sdbPassword "";
sdb:driver "com.mysql.jdbc.Driver" ;
]
.

Testing it

Now, in order to start, I start up the server:

java -cp lib/jena-sdb-1.3.5.jar:lib/jena-arq-2.9.3.jar:lib/mysql-connector-java-5.1.10.jar:fuseki-server.jar org.apache.jena.fuseki.FusekiCmd --config=config.ttl

This should give a response looking like this:

INFO  Configuration file: config.ttl
INFO  Service: :memory
INFO    name = memory
INFO    query = /memory/sparql
INFO    update = /memory/update
INFO  Service: :tdb
INFO    name = tdb
INFO    query = /tdb/sparql
INFO    update = /tdb/update
INFO  Service: :mysql
INFO    name = mysql
INFO    query = /mysql/sparql
INFO    update = /mysql/update
INFO  Dataset path = /memory
INFO  Dataset path = /tdb
INFO  Dataset path = /mysql
INFO  Fuseki 0.2.4 2012-08-03T11:40:41-0700
INFO  Jetty 7.x.y-SNAPSHOT
INFO  Started 2012/12/18 12:09:23 CET on port 3030

So, there is the webinterface now available at http://localhost:3030. The link 'Control Panel' takes one to a selection of the preconfigured services. Choose memory. Lets first create some data, which is done using the 'SPARQL Update' field.

PREFIX rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:   <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ex:   <http://example.org/>
PREFIX zoo:   <http://example.org/zoo/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

INSERT DATA {

ex:dog1    rdf:type         ex:animal .
ex:cat1    rdf:type         ex:cat .
ex:cat     rdfs:subClassOf  ex:animal .
zoo:host   rdfs:range       ex:animal .
ex:zoo1    zoo:host         ex:cat2 .
ex:cat3    owl:sameAs       ex:cat2 .

}

This gives a success message. Go back in the browser, and now we can query the data, using the 'SPARQ Query' field. Please select 'Text' for output.

PREFIX  ex: <http://example.org/>
SELECT ?animal
WHERE
  { ?animal a ex:animal . }

This should give the following result:

-----------------------------
| animal                    |
=============================
| <http://example.org/dog1> |
| <http://example.org/cat2> |
| <http://example.org/cat3> |
| <http://example.org/cat1> |
-----------------------------

If there is only one row, it means the reasoner is not working correctly. This also works with the tdb service.

sam
sam says:
Apr 19, 2014 11:05 AM

Hi,

Thanks for your usefull article.
I am new in ontology and using it, and I have a problem.Could you please help me in the following matter?
I have an ontology and run it on my server using fuseki. It works fine when I send a query as an URL in my browser, like this : "http://my website address:port/ontologyName/saprql?qurery= select ?s ?p ?o where {?s o? <site address>:En}". I need to do such things in my java program, but it does not work when I use the following code:

Query query = QueryFactory.create(s2); //s2 = the query above used in the URL
QueryExecution qExe = QueryExecutionFactory.sparqlService( "http://my website address:port/ontologyName/saprql", query );
ResultSet results = qExe.execSelect();
ResultSetFormatter.out(System.out, results, query) ;

the returned resultSet is empty?! I don't why?

I will appreciate if you could help me out.
Thanks in advance,
Sam

Ravi Kumar
Ravi Kumar says:
Oct 05, 2014 03:39 PM

try
http://my website address:port/ontologyName/query
instead of
http://my website address:port/ontologyName/saprql

Ravo Kumar Singh
Ravo Kumar Singh says:
Jun 20, 2014 02:37 PM

Very nice tutorial. Really helped me a lot. Keep posting such good work.

Lea
Lea says:
Aug 26, 2014 05:45 PM

Nice!!! Can you make owl reasoning works for sql or not yet?

Add comment

You can add a comment by filling out the form below. Plain text formatting.

Question: What is 23 plus 19?
Your answer: