You are on page 1of 2

public static void main(String[] args) { m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); OntDocumentManager dm = m.getDocumentManager(); dm.addAltEntry(ns, file:///C:/travel.owl ); m.

read(ns); //List all the statements in the ontology fileIterator(m); //get type of the resource named BondiBeach System.out.println(findTypeOfResource(ns + #BondiBeach )); } public static void fileIterator(OntModel m) { try { Iterator i = m.listStatements(); if(i.hasNext()) { while (i.hasNext()) { System.out.println(i.next().toString()); } } else System.out.println( ); } catch(Exception e) { e.printStackTrace(); } } public static String findTypeOfResource(String resURI) { Resource res = null; String result = ; try { res = m.getOntResource(resURI); if (res == null) return Resource cannot be found in the ontology ; Iterator i = m.listStatements(res, null, (RDFNode)null); Statement stmt; if(i.hasNext()) { while (i.hasNext()) { stmt = i.next(); if (stmt.getPredicate().toString().compareTo(rdf_ns + type ) == 0) { if (result.compareTo( ) == 0) result = stmt.getObject().toString(); else result = result + , + stmt.getObject().toString(); } } } }

catch (Exception e) { e.printStackTrace(); } return result; } }

You might also like