DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Jena: Listing All Classes And Instances In A Jena Ontology Model

  • submit to reddit
        // Listing all classes and instances in a Jena ontology model

    OntModel model = ModelFactory.createOntologyModel();;
    ExtendedIterator classes = model.listClasses();

    while (classes.hasNext())
      OntClass thisClass = (OntClass);"Found class: " + thisClass.toString());

      ExtendedIterator instances = thisClass.listInstances();

      while (instances.hasNext())
        Individual thisInstance = (Individual);"  Found instance: " + thisInstance.toString());