Using TrOWL with Joseki and TDB

Step 1 Download

Step 2 Set up the environment

Modify your ~/.profile (Mac) ~/.bashrc (Ubuntu) to include the following lines:

export TDBROOT="/path/to/TDB-0.8.x"
export JOSEKIROOT="/path/to/Joseki-3.4.x"
export JENAROOT="/path/to/Jena-2.6.x"
export TROWLROOT="/path/to/trowl-0.x.x"
export PATH="$TDBROOT/bin:$JOSEKIROOT/bin:$PATH"
export CLASSPATH=".:$JENAROOT/lib/*.jar:$TDBROOT/lib/*.jar:$JOSEKIROOT/lib/*.jar:$TROWLROOT/lib/*.jar

Step 3 Make the scripts executable

cd /path/to/Joseki-3.4.x
chmod u+x bin/*
cd /path/to/TDB-0.8.x
chmod u+x bin/*

At this point, you can test if Joseki works by running

cd /path/to/Joseki-3.4.x
./bin/rdfserver

Step 4 Configuring Joseki for your TDB store

  1. Duplicate the joseki-config.ttl file

    cp $JOSEKIROOT/joseki-config.ttl $JOSEKIROOT/joseki-config-mydata-tdb.ttl

  2. Add the tdb namespace prefix to $JOSEKIROOT/ joseki-config- mydata-tdb.ttl

    @prefix tdb: <http://jena.hpl.hp.com/2008/tdb#> .

  3. Comment out #service1 (because we want to use the same ‘sparql’ joseki:serviceRef, and we prefer a FixedDS instead of a general endpoint).

    #<#service1>
    # rdf:type joseki:Service ;
    # rdfs:label "service point" ;
    # joseki:serviceRef "sparql" ; # web.xml must route this name to Joseki
    # joseki:processor joseki:ProcessorSPARQL ;
    # .

  4. Add the following in the “Services” section.
    # Service 3 - SPARQL processor only handling a given dataset in a TDB directory
    <#service3>
    rdf:type joseki:Service ;
    rdfs:label "SPARQL-TDB" ;
    joseki:serviceRef "sparql" ; # web.xml must route this name to Joseki
    # dataset part
    joseki:dataset <#dataset> ;
    # Service part.
    # This processor will not allow either the protocol,
    # nor the query, to specify the dataset.
    joseki:processor joseki:ProcessorSPARQL_FixedDS ;

  5. In the “Datasets” section, add following code:
    [] ja:loadClass "com.hp.hpl.jena.tdb.TDB" . ## Initialize TDB.
    tdb:DatasetTDB rdfs:subClassOf ja:RDFDataset .
    tdb:GraphTDB rdfs:subClassOf ja:Model .
    <#dataset>
    a ja:RDFDataset;
    ja:defaultGraph [
    a ja:InfModel;
    ja:baseModel [
    a tdb:GraphTDB;
    tdb:location "/path/to/mydata-tdb";
    ];
    ];
    .

  6. Turn on Joseki with an additional argument for a non-default configuration file
    cd $JOSEKIROOT
    bin/rdfserver joseki-config-mydata-tdb.ttl
    

Step 5. Configure Joseki to query inferences from data+ontology in a single TDB directory

  1. If the TDB directory contains raw data and ontology data, Joseki can apply a reasoner and return inferenced statements as well as the original statements. To do so, you will need a new Joseki-config -tdb-trowl.ttl.
    cp $JOSEKIROOT/joseki-config-mydata-tdb.ttl $JOSEKIROOT/joseki-config-mydata-tdb-trowl.ttl
    
  2. In $JOSEKIROOT/joseki-config-mydata-tdb-trowl.ttl, replace the following code

    # Service 3 - SPARQL processor for only handling a given dataset in a TDB directory
    <#service3>
    rdf:type joseki:Service ;
    rdfs:label "SPARQL-TDB" ;
    joseki:serviceRef "sparql" ; # web.xml must route this name to Joseki
    # dataset part
    joseki:dataset <#dataset> ;

    with

    # Service 3 - SPARQL processor for only handling a given dataset in a TDB directory
    <#service3>
    rdf:type joseki:Service ;
    rdfs:label "SPARQL-TDB" ;
    joseki:serviceRef "sparql" ; # web.xml must route this name to Joseki
    # dataset part
    joseki:dataset <#dataset_reasoning> ;

  3. After the following code

    <#dataset>
    a ja:RDFDataset;
    ja:defaultGraph [
    a ja:InfModel;
    ja:baseModel [
    a tdb:GraphTDB;
    tdb:location "/path/to/mydata-tdb";
    ];
    ];
    .

    add

    <#dataset_reasoning>
    a ja:RDFDataset;
    ja:defaultGraph [
    a ja:InfModel;
    ja:reasoner [
    ja:reasonerClass "eu.trowl.jena.TrOWLJenaFactory";
    ];
    ja:baseModel <#data_and_ontology_graph>
    ];
    .
    <#data_and_ontology_graph>
    a tdb:GraphTDB ;
    tdb:location "/path/to/mydata-tdb" ;
    .

  4. Run Joseki with an additional argument for a non-default configuration file
    cd $JOSEKIROOT
    bin/rdfserver joseki-config-mydata-tdb-trowl.ttl