mulgara - semantic store

skip navigation


Inferencing Examples Using SOFA and iTQL

This tutorial explains two approaches to using inferencing capabilities of Mulgara: SOFA and the iTQLTM walk command.

The same camera phone ontology, as used in the SOFA tutorial, is used here. This camera phone ontology is an extension of the classic Camera Ontology, with two new classes: Phones and Camera Phones. This example shows how to retrieve the superclasses of the Camera Phone class.

The SOFA API documentation, including the Mulgara classes that provide persistence storage for SOFA objects, is located in <Mulgara install>/docs/api/sofa.


iTQL Inferencing

A running Mulgara server and the CameraPhone.owl ontology are need to complete this tutorial. The CameraPhone.owl file is available in the Resources directory of your Mulgara installation. You can issue the following iTQL commands using either the iTQL shell, the Mulgara ViewerTM or the TMCTM.

Note - In the iTQL commands listed below, replace with the fully qualified hostname for your Mulgara server.


Complete the following steps:

  1. Create the camera phone model and load in the ontology:

    iTQL> create <rmi://>;
    iTQL> load <file:/PATH/TO/TKS/Resources/CameraPhone.owl> into <rmi://>;

  2. Create aliases for RDF Schema and the camera ontology:

    iTQL> alias <> as rdfs;
    iTQL> alias <> as camera;

  3. Perform the following query to retrieve the superclasses:

    iTQL> select $s <rdfs:subClassOf> $o from <rmi://> where
    walk(<camera:CameraPhone> <rdfs:subClassOf> $o and $s <rdfs:subClassOf> $o);

The query should return the following (namespaces have been compacted for clarity):

[ camera:Phone, rdfs:subClassOf, camera:PurchaseableItem ]
[ camera:CameraPhone, rdfs:subClassOf, camera:Phone ]
[ camera:CameraPhone, rdfs:subClassOf, camera:Digital ]
[ camera:Camera, rdfs:subClassOf, camera:PurchaseableItem ]
[ camera:Digital, rdfs:subClassOf, camera:Camera ]

These are the superclasses of a Camera Phone in descending order.


SOFA Inferencing

Sofa API documentation is available in the docs/api/sofa directory of your Mulgara installation.

The following class is a simple class that lists the superclasses of a Camera Phone. It is available as in the Resources directory of your Mulgara installation.

package org.mulgara.sofa.example;

 * Camera Phone Inference Example
import java.util.*;
import org.mulgara.sofa.serialize.owl.*;

public class CameraPhoneInferenceExample {

  public static void main(String[] args) {

    try {
      // Create in memory based Ontology, use TKS ontology model  for persistence
      Ontology ontology = OntoConnector.getInstance().createOntology(
      // Load Camera Phone Ontology
      OWLReader.getReader().read(ontology, "file:CameraPhone.owl ");
      // Get camera phone
      Concept cameraPhone = ontology.getConcept("CameraPhone");
      // Show super classes
      for (Iterator sc = cameraPhone.getSuperConcepts(true).iterator(); sc.hasNext();) {
        Concept superConcept = (Concept);
    } catch (Exception e) {


To run this example:

  1. Retrieve it from the Resources directory of your Mulgara installation and place it in a directory hierarchy like the one shown below:


  2. Compile it from the directory in which you created the above hierarchy:

    javac -classpath <Mulgara directory>/Resources/driver-2.1.jar

  3. Run this example from the Mulgara installation directory,with the following command:

    java -classpath <Mulgara directory>/Resources/driver-1.1.0.jar:example/sofa/java

The following displays on the screen:


These are the superclasses of a Camera Phone in ascending order


Should I use SOFA or iTQL?

Broadly speaking, iTQL is probably more familiar to developers who have built applications around SQL queries in the past. It is also a very hands on, iterative and interactive way of working with Mulgara.

SOFA might appeal more to API programmers who have accessed databases through Object Oriented databases such as Hibernate and J2EE Entity Beans. SOFA is a pure java technology, although it closely models OWL idioms, which are language agnostic.

iTQL can be accessed from a variety of programming languages and technologies, such as web services and might be a better fit in a heterogeneous computing environment. iTQL is currently a more scalable solution when working with very large data sets, although SOFA will be just as scalable in future versions of Mulgara.

Valid XHTML 1.0 TransitionalValid CSS 3.0!