Over a million developers have joined DZone.

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

·
// Listing all classes and instances in a Jena ontology model


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

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

      ExtendedIterator instances = thisClass.listInstances();

      while (instances.hasNext())
      {
        Individual thisInstance = (Individual) instances.next();
        _logger.info("  Found instance: " + thisInstance.toString());
      }
    }
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}