-1

I have ontology file which i have created using Protege.. For my java application i need to retrieve classes and their properties.. I have tried following code but it retrieves only tripples.. I m new to Jena Api and Ontology so pls help

   String URI = "http://www.semanticweb.org/ontologies/2012/0/SBIRS.owl";
   String inputFileName = "D:\\SBIRS.owl";
   System.out.println("File Name" + inputFileName);
   OntModel model = ModelFactory.createOntologyModel();
   StmtIterator si=model.listStatements();
   ResIterator iter=model.listSubjects();
   while(iter.hasNext())
   {
       Resource res=iter.nextResource();
       System.out.println("Property==>" + res.getProperty(null).toString());
       System.out.println("Resource URI==>" + res.getURI());

   }
pitumalkani
  • 127
  • 1
  • 1
  • 7

1 Answers1

2

To list the classes in an OntModel, use the listClasses method. Each returned result from that method will be an instance of the Java class OntClass, which provides convenient access to the triples from the underlying model which define the class.

When you say you need to retrieve "classes and their properties", you could mean two things: the RDF properties of the RDF resource that denotes the class, or the properties which are typically used with instances of the class. In the first case, you can get these through the API on OntClass (and its Java super-classes, e.g. Resource). In the second case, you need to read this how-to.

Ian Dickinson
  • 12,875
  • 11
  • 40
  • 67