Swop
Semantic Web-based Open engineering Platform
tutorial.html
File contents
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>PMO-API tutorial</title>
</head>
<body>
<h1>PMO-API tutorial</h1>
<h2>1. Introduction</h2>
<p>This is a <strong>very preliminary version</strong> of a PMO-API
tutorial.</p>
<p>The <a href="index.html" title="Javadoc documentation">Javadoc API
documentation</a> can be found in this same directory.</p>
<h2>2. Application Programming Interface specification and
implementation</h2>
<p>The PMO-API is conceptually split into two parts:</p>
<ul>
<li>the application programming interface<br />The actual programming
interface consists of Java Interfaces only. As a rule application
programmers should reference only these Java interfaces. This will
guarantee that changes in the underlying implementation won't normally
interfere with the applications that make use of the PMO-API.</li>
<li>the reference implementation of this API<br />The reference
implementation consists of the Java classes that implement the Java
interfaces of the API. The naming convention for these classes is the
name of the interface that it implements plus the postfix "Impl". As a
rule application programmers shouldn't use these classes directly.</li>
</ul>
<h2>3. Tutorial</h2>
<p>The first thing to do is creating a <code>PmoManager</code> object.
This object is the root object to start the PMO-API implementation.</p>
<pre><code> PmoManager pmoMan = PmoManagerFactory.newInstance();</code></pre>
<p>The <code>PmoManager</code> can be used to load an existing PMO file or
to create a new PMO model. Let's load an existing file:</p>
<pre><code> 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());
}</code></pre>
<p>First the reference <code>prodMod</code> that will point to the loaded
model is created. Then the <code>loadModel</code> method of the
<code>PmoManager</code> is called with the URI of the OWL file that we
want to load. The <code>loadModel</code> method may return a product class
model or a product instance model (both have the superclass
<code>ProductModel</code>). Here we expect to get a product class
model.</p>
<pre><code> if (prodMod instanceof ProductClassModel) {
ProductClassModel prodClsMod = (ProductClassModel) prodMod;
...
}</code></pre>
<p>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 ...</p>
<pre><code> 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());
}</code></pre>
<p>Or its properties ...</p>
<pre><code> 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());
}
</code></pre>
<p>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 <code>PmoManager</code> 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.</p>
<pre><code> 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"));</code></pre>
<p>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.</p>
<pre><code> 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());
}</code></pre>
</body>
</html>
Click here to get the file