Get Owl Ontology Model Summary Using Jena
Get Owl Ontology Model Summary Using Jena.
Javadoc available at https://www.javatapas.com/docs/javatapas/jena/GetOwlOntologyModelSummaryUsingJena.html
public static String getSummary(OntModel ontModel){
StringBuffer sb = new StringBuffer();
String NS = ontModel.getNsPrefixURI("");
sb.append("\n==============================\n");
sb.append("Summary of Model: " + NS + "\n");
StmtIterator it1 = ontModel.listStatements();
sb.append(" Statement Count: " + getIteratorCount(it1) + "\n");
ExtendedIterator<Individual> it2 = ontModel.listIndividuals();
sb.append(" Individual Count: " + getIteratorCount(it2) + "\n");
ExtendedIterator<OntClass> it3 = ontModel.listClasses();
sb.append(" All Class Count: " + getIteratorCount(it3) + "\n");
ExtendedIterator<OntClass> it4 = ontModel.listNamedClasses();
sb.append(" Named Class Count: " + getIteratorCount(it4) + "\n");
ExtendedIterator<ObjectProperty> it5 = ontModel.listObjectProperties();
sb.append(" Object Property Count: " + getIteratorCount(it5) + "\n");
ExtendedIterator<AnnotationProperty> it6 = ontModel.listAnnotationProperties();
sb.append(" Annotation Property Count: " + getIteratorCount(it6) + "\n");
ExtendedIterator<DatatypeProperty> it7 = ontModel.listDatatypeProperties();
sb.append(" Datatype Property Count: " + getIteratorCount(it7) + "\n");
sb.append("==============================\n");
return sb.toString();
}
public static int getIteratorCount(Iterator iterator){
int cnt = 0;
while (iterator.hasNext()){iterator.next(); cnt++;}
return cnt;
}