mulgara - semantic store

skip navigation

SHOW SITE NAV
fixed
fluid
straight

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 example.com 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://example.com/server1#cameraphone>;
    iTQL> load <file:/PATH/TO/TKS/Resources/CameraPhone.owl> into <rmi://example.com/server1#cameraphone>;

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

    iTQL> alias <http://www.w3.org/2000/01/rdf-schema#> as rdfs;
    iTQL> alias <http://www.xfront.com/owl/ontologies/camera/#> as camera;

  3. Perform the following query to retrieve the superclasses:

    iTQL> select $s <rdfs:subClassOf> $o from <rmi://example.com/server1#cameraphone> 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 CameraPhoneInferenceExample.java in the Resources directory of your Mulgara installation.

package org.mulgara.sofa.example;

/**
 * Camera Phone Inference Example
 */
import java.util.*;
import net.java.dev.sofa.*;
import net.java.dev.sofa.impl.*;
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(
         "http://www.xfront.com/owl/ontologies/camera/");
      // 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) sc.next();
       System.out.println(superConcept.getId());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

 

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:

    example/sofa/java/org/mulgara/sofa/example/CameraPhoneInferenceExample.java

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

    javac -classpath <Mulgara directory>/Resources/driver-2.1.jar
    example/sofa/java/org/mulgara/sofa/example/CameraPhoneInferenceExample.java

  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
    org.mulgara.sofa.example.CameraPhoneInferenceExample

The following displays on the screen:

Phone
Camera
Digital
PurchaseableItem

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!