PMO-API tutorial

1. Introduction

This is a very preliminary version of a PMO-API tutorial.

The Javadoc API documentation can be found in this same directory.

2. Application Programming Interface specification and implementation

The PMO-API is conceptually split into two parts:

3. Tutorial

The first thing to do is creating a PmoManager object. This object is the root object to start the PMO-API implementation.

   PmoManager pmoMan = PmoManagerFactory.newInstance();

The PmoManager can be used to load an existing PMO file or to create a new PMO model. Let's load an existing file:

   ProductModel prodMod = null;
   try {
      prodMod = pmoMan.loadModel("http://www.swop-project.eu/ontologies/css/css_ga.owl");
   } catch (PmoException e) {
      System.err.println("Load model exception: " + e.getMessage());
   }

First the reference prodMod that will point to the loaded model is created. Then the loadModel method of the PmoManager is called with the URI of the OWL file that we want to load. The loadModel method may return a product class model or a product instance model (both have the superclass ProductModel). Here we expect to get a product class model.

   if (prodMod instanceof ProductClassModel) {
      ProductClassModel prodClsMod = (ProductClassModel) prodMod;

      ...

   }

The product class model reference prodClsMod is the entry object to traverse all the information associated with this model. For example the direct decomposition parts of this product class ...

   System.out.println("Parts of " + prodClsMod.getProductClassURI());
   Iterator<DirectPart> partIter = prodClsMod.listParts();
   while (partIter.hasNext()) {
      DirectPart part = partIter.next();
      System.out.print("Part type: " + part.getProductClassModel().getProductClassURI());
      System.out.print(" min. card.: " + part.getMinCardinality());
      System.out.println(" max. card.: " + part.getMaxCardinality());
   }

Or its properties ...

   System.out.println("Properties:");
   Iterator<DataProperty> propIter = prodClsMod.listProperties();
   while (propIter.hasNext()) {
      DataPropertyImpl prop = (DataPropertyImpl) propIter.next();
      System.out.println(prop.getShortName() 
        + " (" + prop.getValueType() 
        + ") = " + prop.getDefaultValue() 
        + " " + prop.getUnit());
   }

An OWL file can also be loaded from a local file system. If this OWL file contains import statements of ontologies that are also stored locally the PmoManager should be informed in which directories to look for them. By default the same directory is searched first, then a user specified list of directories is searched in a fixed order and finally the missing ontology is searched on the web.

   pmoMan.addSearchDirectory("C:\\Documents and Settings\\wspa\\Desktop\\SWOP_Viewer\\ontologies\\pmo");
   pmoMan.addSearchDirectory("C:\\Documents and Settings\\wspa\\Desktop\\SWOP_Viewer\\ontologies\\d23");
   prodMod = pmoMan
      .loadModel(new File("C:\\Documents and Settings\\wspa\\Desktop\\SWOP_Viewer\\ontologies\\d23\\facade.owl"));

Finally, all models in the same directory (remote or on the local disk) can be loaded in one action: loadIndex(). The return value is an iterator object which can be used to loop over all encountered models.

   PmoManager pmoMan = PmoManagerFactory.newInstance();
   try {
      Iterator<ProductModel> pmIter = pmoMan.loadIndex(new File(
         "C:\\Development\\Java\\workspace\\Ontologies\\css\\index.owl"));
      // Iterator<ProductModel> pmIter = pmoMan
      // .loadIndex("http://www.swop-project.eu/ontologies/css/index.owl");

      while (pmIter.hasNext()) {
         ProductModel pm = pmIter.next();
            System.out.print("Ontology: " + pm.getShortName());
         if (pm instanceof ProductClassModel) {
            System.out.println(" (ProductClassModel)");
         } else if (pm instanceof ProductInstanceModel) {
            System.out.println(" (ProductInstanceModel)");
         } else if (pm instanceof ShapeClassModel) {
            System.out.println(" (ShapeClassModel)");
         }
      }
   } catch (PmoException e) {
      System.err.println("Loading exception: " + e.getMessage());
   }