Difference between revisions of "BeanShell"

From Protege Wiki

Jump to: navigation, search
(Created page with 'As a Protege developer, I have a unique ability to answer complex questions about large ontologies. All I have to do is to start Protege inside eclipse, open the ontology and se…')
 
Line 1: Line 1:
 +
= The BeanShell =
 +
 
As a Protege developer, I have a unique ability to answer complex questions about large ontologies.  All I have to do is to start Protege inside eclipse, open the ontology and set a breakpoint and I will have access to a full array of powerful Java tools for analyzing the ontology.  These tools range from the full set of OWL api features, direct access to reasoners and the ability to make a complex script out of simple primitives.  I have often thought that this power would be much more useful in the hands of the end user but it has been unclear how to get there.  What is really needed is a very powerful scripting language.
 
As a Protege developer, I have a unique ability to answer complex questions about large ontologies.  All I have to do is to start Protege inside eclipse, open the ontology and set a breakpoint and I will have access to a full array of powerful Java tools for analyzing the ontology.  These tools range from the full set of OWL api features, direct access to reasoners and the ability to make a complex script out of simple primitives.  I have often thought that this power would be much more useful in the hands of the end user but it has been unclear how to get there.  What is really needed is a very powerful scripting language.
  
Line 8: Line 10:
 
Here the ''mgnr'' is the Protege Model Manager which keeps track of such things as which ontologies are displayed, how enties in the ontology should be display and the active OWL reasoner.
 
Here the ''mgnr'' is the Protege Model Manager which keeps track of such things as which ontologies are displayed, how enties in the ontology should be display and the active OWL reasoner.
  
Some documentation for the beanshell can be found [http://code.google.com/p/co-ode-owl-plugins/wiki/BeanshellView|here].
+
Some documentation for the beanshell can be found [http://code.google.com/p/co-ode-owl-plugins/wiki/BeanshellView here].  My idea in writing this page was to supplement that page with some examples of queries that I have used in my work.  I am just starting this page so I will start with a query that is so simple that it could have been done even in a simple language like SPARQL.  I will look at properties that are punned with each other.  Any such problem represents a problem in the ontology.  To make this interesting I will show what happens when I run this script on the [http://xmlns.com/foaf/0.1/ foaf ontology] which is known to have some problems as an OWL 2 file.  The script is as follows:
 +
<pre>
 +
OWLOntology ontology = mngr.getActiveOntology();
 +
print("\nActive Ontology = " + ontology);
 +
 
 +
for (OWLAnnotationProperty ap : ontology.getAnnotationPropertiesInSignature()) {
 +
    if (ontology.containsDataPropertyInSignature(ap.getIRI())) {
 +
      print("The annotation property " + ap.toString()
 +
                                + " is also a data property");
 +
    }
 +
}
 +
 
 +
for (OWLAnnotationProperty ap : ontology.getAnnotationPropertiesInSignature()) {
 +
    if (ontology.containsObjectPropertyInSignature(ap.getIRI())) {
 +
      print("The Annotation Property " + ap.toString()
 +
                                + " is also an object property");
 +
    }
 +
}
 +
 
 +
for (OWLDataProperty dp : ontology.getDataPropertiesInSignature()) {
 +
    if (ontology.containsObjectPropertyInSignature(dp.getIRI())) {
 +
      print("The data property " + dp.toString()
 +
                      + " is also an object property");
 +
    }
 +
}
 +
</pre>
 +
This script can either be run interactively:
 +
<pre>
 +
bsh % ontology = mngr.getActiveOntology();
 +
bsh % print(ontology);
 +
Ontology(<http://xmlns.com/foaf/0.1/> [Axioms: 550] [Logical axioms: 157])
 +
bsh %
 +
</pre>
 +
or by being copied into a file and then run with the ''Run script'' command.  The output looks like this:
 +
<pre>
 +
Active Ontology = Ontology(<http://xmlns.com/foaf/0.1/> [Axioms: 550] [Logical axioms: 157])
 +
The annotation property <http://xmlns.com/foaf/0.1/name> is also a data property
 +
The data property <http://xmlns.com/foaf/0.1/yahooChatID> is also an object property
 +
The data property <http://xmlns.com/foaf/0.1/mbox_sha1sum> is also an object property
 +
The data property <http://xmlns.com/foaf/0.1/jabberID> is also an object property
 +
The data property <http://xmlns.com/foaf/0.1/icqChatID> is also an object property
 +
The data property <http://xmlns.com/foaf/0.1/msnChatID> is also an object property
 +
The data property <http://xmlns.com/foaf/0.1/aimChatID> is also an object property
 +
</pre>
 +
This is useful information to know about this ontology because each of these puns represents a potential problem for ontologies that import the foaf ontology and are saved in the popular RDF/XML format.

Revision as of 11:52, May 24, 2011

The BeanShell

As a Protege developer, I have a unique ability to answer complex questions about large ontologies. All I have to do is to start Protege inside eclipse, open the ontology and set a breakpoint and I will have access to a full array of powerful Java tools for analyzing the ontology. These tools range from the full set of OWL api features, direct access to reasoners and the ability to make a complex script out of simple primitives. I have often thought that this power would be much more useful in the hands of the end user but it has been unclear how to get there. What is really needed is a very powerful scripting language.

The beanshell (a CO-ODE plugin developed at the University of Manchester) can fill some of these needs. The primary disadvantage of the bean shell is that it requires some experience with Java and knowledge of the OWL API. This will severely limit the audience but I thought it would still be useful to include some pages on how to use the beanshell. The beanshell also requires some understanding of the Protege API but to start with all that is really needed is to know one call:

      ontology = mngr.getActiveOntology();

Here the mgnr is the Protege Model Manager which keeps track of such things as which ontologies are displayed, how enties in the ontology should be display and the active OWL reasoner.

Some documentation for the beanshell can be found here. My idea in writing this page was to supplement that page with some examples of queries that I have used in my work. I am just starting this page so I will start with a query that is so simple that it could have been done even in a simple language like SPARQL. I will look at properties that are punned with each other. Any such problem represents a problem in the ontology. To make this interesting I will show what happens when I run this script on the foaf ontology which is known to have some problems as an OWL 2 file. The script is as follows:

OWLOntology ontology = mngr.getActiveOntology();
print("\nActive Ontology = " + ontology);

for (OWLAnnotationProperty ap : ontology.getAnnotationPropertiesInSignature()) {
    if (ontology.containsDataPropertyInSignature(ap.getIRI())) {
       print("The annotation property " + ap.toString()
                                 + " is also a data property");
    }
}

for (OWLAnnotationProperty ap : ontology.getAnnotationPropertiesInSignature()) {
    if (ontology.containsObjectPropertyInSignature(ap.getIRI())) {
       print("The Annotation Property " + ap.toString() 
                                + " is also an object property");
    }
}

for (OWLDataProperty dp : ontology.getDataPropertiesInSignature()) {
    if (ontology.containsObjectPropertyInSignature(dp.getIRI())) {
       print("The data property " + dp.toString() 
                      + " is also an object property");
    }
}

This script can either be run interactively:

bsh % ontology = mngr.getActiveOntology();
bsh % print(ontology);
Ontology(<http://xmlns.com/foaf/0.1/> [Axioms: 550] [Logical axioms: 157])
bsh % 

or by being copied into a file and then run with the Run script command. The output looks like this:

Active Ontology = Ontology(<http://xmlns.com/foaf/0.1/> [Axioms: 550] [Logical axioms: 157])
The annotation property <http://xmlns.com/foaf/0.1/name> is also a data property
The data property <http://xmlns.com/foaf/0.1/yahooChatID> is also an object property
The data property <http://xmlns.com/foaf/0.1/mbox_sha1sum> is also an object property
The data property <http://xmlns.com/foaf/0.1/jabberID> is also an object property
The data property <http://xmlns.com/foaf/0.1/icqChatID> is also an object property
The data property <http://xmlns.com/foaf/0.1/msnChatID> is also an object property
The data property <http://xmlns.com/foaf/0.1/aimChatID> is also an object property

This is useful information to know about this ontology because each of these puns represents a potential problem for ontologies that import the foaf ontology and are saved in the popular RDF/XML format.

Personal tools