0

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.

M D
  • 67
  • 1
  • 11
  • 1
    What do you mean "it doesn't work in Protégé"? Protege is a OWL ontology editor; it's not a Java compiler. You need to describe what you're doing in more detail, along with what you _expected_ to happen, and what's _actually_ happening. – Joshua Taylor Nov 29 '13 at 17:01
  • I mean when I import the .owl file I created in my java code to protege and I add an individual to "A" class it doesn't add to the "B" class. – M D Nov 29 '13 at 17:40
  • 1
    Are you writing a stand alone application? A Protege plugin? There's a _whole_ lot that you haven't told us. Should `instaneAdded` be `instanceAdded` (note the `c`)? If you use an `@Override` annotation, you'd get an error about trying to override a not-previously-defined method. – Joshua Taylor Nov 29 '13 at 17:48

1 Answers1

2

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).

Community
  • 1
  • 1
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • you are right @Joshoua.that was a silly mistake I think I could never find out.I fix it and works well,Thank you so much. – M D Nov 29 '13 at 18:18
  • @MD No problem, mona. Be sure to use the `@Override` annotation, and you'll avoid this particular kind of problem in the future. – Joshua Taylor Nov 29 '13 at 18:29