I want to import and list semantic web (owl) file's classes into the eclipse. I am new to eclipse hence i might make simple mistakes but in my position it is not that simple. Throughout some research i found a code which i have used in eclipse. I am getting an error on public void testAddAxioms() specifically on the void. The code is below:
public static void main(String[] args) {
File file = new File("file:c:/Users/DTN/Desktop/Final SubmissionFilteringMechanism_Ontology.owl");
OWLOntologyManager m = OWLManager.createOWLOntologyManager();
OWLDataFactory f = OWLManager.getOWLDataFactory();
OWLOntology o = null;
public void testAddAxioms() {
try {
o = m.loadOntologyFromOntologyDocument(Ont_Base_IRI);
OWLClass clsA = f.getOWLClass(IRI.create(Ont_Base_IRI + "ClassA"));
OWLClass clsB = f.getOWLClass(IRI.create(Ont_Base_IRI + "ClassB"));
OWLAxiom ax1 = f.getOWLSubClassOfAxiom(clsA, clsB);
AddAxiom addAxiom1 = new AddAxiom(o, ax1);
m.applyChange(addAxiom1);
for (OWLClass cls : o.getClassesInSignature()) {
EditText edit = (EditText) findViewById(R.id.editText1);
edit.setText((CharSequence) cls);
}
m.removeOntology(o);
} catch (Exception e) {
EditText edit = (EditText) findViewById(R.id.editText1);
edit.setText("Not successfull");
}
}
}
2 Answers 2
You can't declare a method inside of another method. That's essentially what you're doing inside of main.
Move your declaration of testAddAxioms outside of main, as such:
public static void main(String[] args) {
// code omitted for brevity
}
public void testAddAxioms() {
// code omiited for brevity
}
Comments
To call your testAddAxioms() method you need to first declare it outside your main() method. It can be in the same class, or in a new class.
public class YourClass {
public static void main(String[] args) {
File file = new File("...");
OWLOntologyManager m = OWLManager.createOWLOntologyManager();
OWLDataFactory f = OWLManager.getOWLDataFactory();
OWLOntology o = null;
// removed your method from here
}
public void testAddAxioms() {
...
}
}
To call it (from the same place where you had placed it), you will have to change its declaration to accept the types you are sending to it:
public void testAddAxioms(OWLOntology o, OWLOntologyManager m, OWLDataFactory f) { ...}
And then, in your main() method, to instantiate an object of your class to be able to call it.
YourClass obj = new YourClass();
obj.testAddAxioms(o, m, f);
Another way to call it is to declare the method static:
public static void testAddAxioms(OWLOntology o, OWLOntologyManager m, OWLDataFactory f) { ...}
Then you don't need to create any object and can simply call:
testAddAxioms(o, m, f);
But you should review your code carefully. You are declaring File file but are not using it. Perhaps you need to pass it to some method or constructor when initializing the objects you pass to the method. If you need it inside the method, you will have to add an extra argument to it.
voidin your main method.new File("c:/Users/D...without full URL syntax.