Search code examples
javaeclipseowl-api

add data in ontology with owl api using html form in eclipse


I am using OWL Api 3.5 in eclipse kepler with a simple ontology in Protege 4. I have uploaded an ontology from local files and add new class "clsN" in it with individual "M2". what I want is to add this class "clsN" and individual "M2" in ontology through HTML form fields. Idon't how to do this.

kindly give me some idea related to this. Here is the my java class code.

public class Ontologytest {
    public static void main(String[] args) throws OWLOntologyCreationException, OWLOntologyStorageException {

        OWLOntologyManager m = OWLManager.createOWLOntologyManager();
        File file = new File("C:/Users/hhh/Desktop/test.owl");

        OWLDataFactory f = OWLManager.getOWLDataFactory();
        OWLOntology o;
        o = m.loadOntologyFromOntologyDocument(file);
        OWLClass clsN = f.getOWLClass(IRI.create("urn:test#ClassN"));
        OWLDeclarationAxiom declarationAxiom = f.getOWLDeclarationAxiom(clsN);
        m.addAxiom(o, declarationAxiom);
        OWLNamedIndividual M2 = f.getOWLNamedIndividual(IRI.create("urn:test" + "#M2"));
        OWLClassAssertionAxiom clsD = f.getOWLClassAssertionAxiom(clsN, M2);
        m.addAxiom(o, clsD);
    }
}

Solution

  • The only thing missing is

    m.saveOntology(o);
    

    to save the newly added class and individual in your file.