javajenafusekitriplestoretdb

How to create a Jena Triple Store based on an existing OWL file using Jena API, Fuseki and TDB?


I am currently working on a project where there is an initial .owl file that contains the base schema for our ontology. We load this file using the Jena API and perform different manipulations on it, such as adding ontology classes and individuals.

We seek to migrate the system to a triple store meaning that, instead of reading and writing .owl files all the time, we wish to load the initial .owl file once and then perform further operations on a server.

I did not quite grasp the concepts explained by the Jena documentation, because they seem to diverge in all directions; what I understood, however, is that we must use Fuseki embedded and Jena TDB for this. I tried the following code (the OntModel parameter in this case contains the schema for our ontology):

public Store(OntModel model) {
    Dataset ds = DatasetFactory.assemble(model);
    File dsDir = new File(ClassLoader.getSystemClassLoader().getResource("ds/")
            .getFile());

    ds.begin(ReadWrite.WRITE);

    server = FusekiServer.create().add(dsDir.getAbsolutePath(), ds).build();
}

This gives me the following error: org.apache.jena.sparql.ARQException: No root found for type <http://jena.hpl.hp.com/2005/11/Assembler#RDFDataset>. Please provide me with some examples of usage.


Solution

  • DatasetFactory.assemble means construct a new model from a description which is also held in RDF (these are called assemblers in Jena).

    If you want a Fuseki server, start one and use the UI to create dataset and load a file.

    OR

    To load data:

    Create and load a TDB dataset using the command line tdbloader into a directory "DIRECTORY_NAME". This needs doing only once.

    To run the server each time:

    Dataset ds = TDBFactory.createDataset("DIRECTORY_NAME");
    FusekiServer server = FusekiServer.create().add("/myName", ds).build();
    server.start();
    

    and the dataset HTTP SPARQL interface (programmatic) is available at http://localhost:3030/myName.

    If you want a query UI, use the full Fuseki server.