Question

I want to implement events to ontology. For example by adding an individual to one class it's added to another class. Following the instructions in ProtegeOWL_API_Advanced_Topics I wrote this:

      JenaOWLModel model=ProtegeOWL.createJenaOWLModel();
      OWLNamedClass c1= model.createOWLNamedClass("A");
      OWLNamedClass c2= model.createOWLNamedClass("B");
      c1.addClassListener( new ClassAdapter(){
       public void instaneAdded(RDFSClass c1,RDFSClass c2,RDFResource instance) {
         String s= instance.getName();
         c2.createInstance(s);
       }
       });

Isn't it right way? Because it doesn't work in protege.

Was it helpful?

Solution

I bet that in your new class adapter, you meant to define a method instanceAdded, not instaneAdded (note the c in the former). If you follow best practices and use the @Override annotation, you would have gotten an error about not being able to override a method that wasn't previously defined.

  public void instaneAdded(RDFSClass c,RDFSClass c2,RDFResource instance) {
              ************

The advice to add @Override isn't just mine. If you take a look at the accepted answer to What does @Override mean? mentions that by declaring your intent to override a method, you will get warnings if there isn't such a method to override (as in this case).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top