| Previous Next Contents References Traversing the BioPax OWL
Ontology with Protégé Java API's
The Protégé
project includes a library for reading and manipulating OWL
documents. This is described in The Protégé-OWL API -
Programmer's Guide15.
This section
demonstrates the Protégé OWL API's for reading an OWL file.
The program
traverses the BioPax Level 2 OWL file and generates HTML documentation
for the ontology. The source code is in file BioPaxLevel2.java. The
generated HTML file is bio_pax_level2.html.
|
|
The main method then iterates over the classes again to give a place for the select widget to jump to.
private static StringBuffer getClassList(OWLModel owlModel) {
StringBuffer sb = new StringBuffer(
" <p>Go to BioPax Class: " +
" <select id='jump_select' onchange='jump(this)';>\n");
Collection classes = owlModel.getUserDefinedOWLNamedClasses();
for (Iterator it = classes.iterator(); it.hasNext();) {
OWLNamedClass cls = (OWLNamedClass) it.next();
sb.append(" <option value='" + cls.getName() + "'>" + cls.getName() + "</option>\n");
}
sb.append(
" </select></p>\n" +
" </form>\n");
return sb;
}
Collection classes = owlModel.getUserDefinedOWLNamedClasses();
int i = 0;
for (Iterator it = classes.iterator(); it.hasNext();) {
OWLNamedClass cls = (OWLNamedClass) it.next();
detail.append(
" <a name='" + cls.getName() + "'/>" +
" <h2>Class " + cls.getName() + "</h2>\n" +
" <p>Parent: ");
The next few lines find the parent class, which can hyperlink to it's own definition.
Collection superclasses = cls.getNamedSuperclasses();
for (Iterator superclassIt = superclasses.iterator(); superclassIt.hasNext(); ) {
String parent = ((OWLNamedClass)superclassIt.next()).getName();
detail.append("<a href='#" + parent + "'>" + parent + "</a> ");
}
detail.append("</p>\n");
Finally, the program appends the comments to the HTML file.
detail.append(
" <p id='" + cls.getName() + "' tabindex='" + i + "'/>\n");
Collection comments = cls.getComments();
for (Iterator commentIt = comments.iterator(); commentIt.hasNext(); ) {
detail.append(commentIt.next());
}
detail.append("</p<\n");
i++;
}
html.append(detail);
The markup tags for the end of the HTML file are added and the
buffer is written out to the file bio_pax_level2.html using the method
writeToFile(). To run the program enter the follow command
at a command
prompt.
>java -cp classes;lib/AbstractSyntax.jar;lib/commons-lang-2.0.jar;lib/commons-logging.jar;lib/icu4j.jar;lib/jena.jar;lib/OWLDoc.jar;lib/protege.jar;\
lib/protege-owl.jar;lib/standard-extensions.jar net.medicalcomputing.owl.example.BioPaxLevel2
Assuming that the class file is in a directory called 'classes' and all the jar files are in a directory called 'lib'. The class file is BioPaxLevel2.class.
Previous Next
Contents References