
import org.semanticweb.owlapi.apibinding.OWLManager;
	import org.semanticweb.owlapi.io.*;
	import org.semanticweb.owlapi.model.*;
	import org.semanticweb.owlapi.util.SimpleIRIMapper;

	import java.io.File;
	import java.io.FileNotFoundException;
	import java.io.IOException;
	import java.net.URI;
	import java.net.UnknownHostException;
	import java.util.Map;
        import org.semanticweb.owlapi.util.DefaultPrefixManager;
        import org.semanticweb.owlapi.vocab.OWLFacet;
        import org.semanticweb.owlapi.vocab.OWL2Datatype;


public class ontology1 {
    public static void main(String[] args) {

       try {
       OWLOntology animal;
       OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
       OWLDataFactory dataFactory = manager.getOWLDataFactory();
       IRI iri = IRI.create("http://www.test.com/ontologies/testont.owl");
       File file = new File("C:/Users/Syed/Desktop/animal.owl");
       animal = manager.loadOntologyFromOntologyDocument(file);
       manager.addIRIMapper(new SimpleIRIMapper(iri, IRI.create(file)));
       IRI ontologyIRI = IRI.create("http://www.test.com/ontologies/testont.owl");
       animal = manager.loadOntology(ontologyIRI);
       PrefixManager pm = new DefaultPrefixManager("http://www.test.com/ontologies/testont.owl");
       OWLClass plant = dataFactory.getOWLClass(":plant", pm);
       OWLNamedIndividual apple = dataFactory.getOWLNamedIndividual(":tree", pm);
       OWLClassAssertionAxiom axiom = dataFactory.getOWLClassAssertionAxiom(plant, apple);
       manager.addAxiom(animal,axiom);

       OWLIndividual lion = dataFactory.getOWLNamedIndividual(":lion", pm);
       OWLIndividual cow = dataFactory.getOWLNamedIndividual(":herbivore", pm);
       OWLObjectProperty eats = dataFactory.getOWLObjectProperty(IRI.create(animal + "#eats"));
       OWLObjectPropertyAssertionAxiom axiom1 = dataFactory.getOWLObjectPropertyAssertionAxiom(eats, lion, cow);
       manager.addAxiom(animal,axiom1);
       
       OWLDatatype integer = dataFactory.getIntegerOWLDatatype();
       OWLLiteral hundred = dataFactory.getOWLLiteral(100);
       OWLDatatypeRestriction range = dataFactory.getOWLDatatypeRestriction(integer, OWLFacet.MIN_INCLUSIVE, hundred);
       OWLDataProperty tall = dataFactory.getOWLDataProperty(IRI.create(animal + "#tall"));
       OWLDataPropertyRangeAxiom axiom2 = dataFactory.getOWLDataPropertyRangeAxiom(tall,range);
       manager.addAxiom(animal,axiom2);
       manager.saveOntology(animal);
       }

       catch (OWLException e) {
       e.printStackTrace();
       }

    }

}
