Menu

Ontotext

Access Methods

There are a variety of ways to integrate or use OWLIM programmatically, the recommended method being via the Sesame openRDF API. In fact, OWLIM is built around the RDF data model classes from Sesame and for this reason Sesame is the preferred API to use and the most efficient. Unless stated otherwise, the performance figures shown on the benchmark pages were obtained using OWLIM through Sesame. As of OWLIM 4.2, the Sesame API fully supports SPARQL 1.1.

Nevertheless, there are other ways to use OWLIM and this page explains the various options and some of their advantages and disadvantages.

Summary of access methods

The following table gives a simple comparison between the various methods for accessing OWLIM:

  Sesame Jena ORDI
RDF Syntaxes RDF/XML, RDF/XML-Abbrev, N-Triple, N3, Turtle RDF/XML, N-Triples, N3, Turtle, TriG, TriX (Same as Sesame)
Query languages SPARQL, SeRQL SPARQL (Same as Sesame)
SPARQL 1.0
SPARQL 1.1  
SPARQL Update  
Triplesets    

Specific details about each method are given in the sections below.

Sesame openRDF framework

Sesame openRDF is an open-source framework for the storage of, inferencing over and querying of RDF data. The framework consists of a number of Java APIs and utilities, as well as some default implementations of storage and inferencing components.

OWLIM is built around the RDF data model classes from Sesame and for this reason Sesame is the preferred API to use and the most efficient.

The Sesame framework consists of a number of independent components that share the common RDF Data Model (a component for describing RDF statements, resources, predicates and values). OWLIM uses the RDF Data Model classes throughout. Sesame combines all the syntax related classes in to the Rio component that contains all the sterilizers and parsers for the many RDF syntaxes supported. This component is extensible and users can add support for custom RDF syntaxes.

The SAIL component (Storage And Inference Layer) contains the classes and interfaces for accessing various storage and inference implementations in a standard way. OWLIM is implemented as a SAIL plug-in to the Sesame framework here.

At a higher level, the Repository API provides uniform application layer access to Sesame and includes methods for loading/exporting RDF data, preparing and executing queries and so on. The framework includes a console application, a command-line utility for various administration tasks, such as creating/deleting repositories, importing/exporting RDF data, etc.

To use OWLIM via the Sesame API, the typical sequence of events is to use an RDF description of a repository contained in 'graph' and identified by 'repositoryNode' as follows:

    // Create a manager for local repositories
    repositoryManager = new LocalRepositoryManager(new File("."));

    // Initialize the repository manager
    repositoryManager.initialize();

    // Create a configuration object from the configuration file and add it
    // to the repositoryManager
    RepositoryConfig repositoryConfig = 
        RepositoryConfig.create(graph, repositoryNode);
    repositoryManager.addRepositoryConfig(repositoryConfig);

    // Get the repository to use
    repository = repositoryManager.getRepository("owlim");

    // Open a connection to this repository
    repositoryConnection = repository.getConnection();
    repositoryConnection.setAutoCommit(false);
	
    // ... use the connection ...
	
    // It is very important to close down properly in order to free resources
    repositoryConnection.close();
    repository.shutDown();
    repositoryManager.shutDown();

Furthermore, Sesame includes HttpServer and HttpClient components that allow a repository to be accessed remotely using Servlet technology. The client side integrates seamlessly with the Repository API providing uniform access to local and remote repositories. The server side component includes Web applications (.war archives) for exposing repositories via a standard Servlet container, e.g. Tomcat, as well as a Workbench application that provides commonly used administrative functions that can be accessed via a browser.

To use a remote repository, instead of one managed by a LocalRepositoryManager, use the following to get access to a remote repository:

    // Use this class to access a remote repository advertised by an
    // instance of the Sesame HTTP Server.
    repositoryManager = new 
        RemoteRepositoryManager( "http://192.168.1.25:8080/openrdf-sesame" );

This example uses the default Tomcat port number. Replace the IP address with the hostname or IP address of your Tomcat instance.

Sesame supports the current W3C SPARQL recommendation (SPARQL 1.0), and SPARQL 1.1 Query specification which offers new features such as: Aggregates, Subqueries, Negation, Expressions in the SELECT clause, Property Paths, Assignment, Short form for CONSTRUCT and an expanded set of functions and operators. Federation will be supported in a subsequent release.

Jena

Jena is a Java framework for building Semantic Web applications. It provides a programmatic environment for RDF, RDFS, OWL and SPARQL and includes a rule-based inference engine. Only OWLIM-SE (version 3.4 onwards) can be accessed using Jena at present.

Access to OWLIM-SE via the Jena framework is achieved with a special adapter, which is essentially an implementation of the Jena ARQ interface that provides access to individual triples managed by a OWLIM-SE repository through the Sesame API interfaces.

The Jena adapter for OWLIM-SE is not a general purpose Sesame adapter and cannot be used to access any Sesame compatible repository, because it utilizes an internal OWLIM-SE API to provide more efficient methods for processing RDF data and evaluating queries.

The adapter comes with its own implementation of a Jena 'assembler' factory to make it easier to instantiate and use with those related parts of the Jena framework, although one can instantiate an adapter directly by providing an instance of a Sesame SailRepository (an OWLIM-SE OWLIMRepository implementation). Query evaluation is controlled by the ARQ engine, but specific parts of a Query (mostly batches of statement patterns) are evaluated natively through a modified StageGenerator plugged into the Jena runtime framework for efficiency. This also avoids unnecessary cross-API data transformations during query evaluation.

The Jena adapter can be used as follows, where a 'repositoryConnection' is obtained as in the example in the Sesame section above:

    import com.ontotext.jena.SesameDataset;
	
    // Create the DatasetGraph instance
    SesameDataset dataset = new SesameDataset(repositoryConnection);

From now on the SesameDataset object can be used through the Jena API as regular Dataset, e.g. to add some data to it one could do something like the following:

    Model model = ModelFactory.createModelForGraph(dataset.getDefaultGraph());
    Resource r1 = model.createResource("http://example.org/book#1");
    Resource r2 = model.createResource("http://example.org/book#2");
    r1.addProperty(DC.title, "SPARQL - the book")
        .addProperty(DC.description, "A book about SPARQL");
    r2.addProperty(DC.title, "Advanced techniques for SPARQL");

The performance of OWLIM-SE when used through Jena is quite similar to using it through the Sesame APIs. For most of the scenarios and tasks OWLIM-SE can deliver considerable performance improvements when used as a replacement for Jena's own native RDF backend TDB. More information is provided on the "OWLIM through Jena Performance" page.

ORDI

The Ontology Representation and Data Integration (ORDI) framework is an open-source ontology middleware developed in Java. ORDI enables enterprise data integration via an RDF-like data model. The ORDI data model introduces some basic notions and data-structures, which are then used for ontology and data representation.

The main advantage for accessing OWLIM through ORDI is that the triple-set data structures are exposed. This extension to the basic RDF data model is explained on page 6 of the ORDI Second Generation Specification. This data model extends the concept of a quad (triple with context) to include a collection of tripleset identifiers (URIs):

<S, P, O, C, {TS1,...,TSn}>

Using this model, a statement can be associated with a tripleset by appending the triple set identifier (URI) to the list associated with that statement. This enables a many-to-many relationship between statements and triple-sets without the need to duplicate statements. Thus triplesets are a means to identify sub-sets of statements that span default and named graphs. Triplesets can be used to limit the scope of query evaluation, i.e. SPARQL queries can be evaluated over just a subset of the total graph by specifying the tripleset identifier.

The following example shows how to iterate over only those statements associated with the tripleset http://example.org/tripleset1 with any subject and object, but with the predicate equal to http://example.org/property1:

    import com.ontotext.ordi.Factory;
    import com.ontotext.ordi.exception.ORDIException;
    import com.ontotext.ordi.iterator.CloseableIterator;
    import com.ontotext.ordi.tripleset.TConnection;
    import com.ontotext.ordi.tripleset.TFactory;
    import com.ontotext.ordi.tripleset.TSource;
    import com.ontotext.ordi.tripleset.TStatement;
    import com.ontotext.ordi.tripleset.impl.TFactoryImpl;
    ...
    TConnection connection = source.getConnection();
    // create RDF type factory
    TFactory factory = new TFactoryImpl();
    Resource subj = null;
    URI pred = factory.createURI("http://example.org/property1");
    Value obj = null;
    URI tripleset = factory.createURI("http://example.org/tripleset1");
    try {
        CloseableIterator iterator =
            connection.search(subj, pred, obj, null, tripleset);
        while(iterator.hasNext()) {
            TStatement statement = iterator.next();
        }
    } catch (ORDIException e) {
        ...
    }