Note that there are some explanatory texts on larger screens.

plurals
  1. POIssues to list classes and subclasses with Jena
    text
    copied!<p>I'm not getting to list all subclasses of a class. I list the classes, my algorithm checks if each class has a subclass. If true, was to list all subclasses. But this doesn´t happen, it seems to ignore the condition "if (essaClasse.hasSubClass). Can anyone help me? Bellow the code part.</p> <p>Thanks!</p> <p>Debora (Rio de Janeiro - Brasil)</p> <p>The full code:</p> <pre><code>package testejena; import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.util.FileManager; import com.hp.hpl.jena.util.iterator.ExtendedIterator; import java.io.InputStream; import java.util.Iterator; public class testeProp { static final String inputFileName = "OBRecortada3.owl"; public static void main(String args[]) { try { //create the reasoning model using the base OntModel inf = ModelFactory.createOntologyModel(); // use the FileManager to find the input file InputStream in = FileManager.get().open(inputFileName); if (in == null) { throw new IllegalArgumentException("File: " + inputFileName + " not found"); } inf.read(in, ""); String URI = "http://www.owl-ontologies.com/OntologyBase.owl#"; ExtendedIterator classes = inf.listClasses(); while (classes.hasNext()) { OntClass essaClasse = (OntClass) classes.next(); String vClasse = essaClasse.getLocalName().toString(); if (essaClasse.hasSubClass()) { System.out.println("Classe: " + vClasse); OntClass cla = inf.getOntClass(URI + vClasse); for (Iterator i = cla.listSubClasses(); i.hasNext();) { OntClass c = (OntClass) i.next(); System.out.print(" " + c.getLocalName() + " " + "\n"); } } } } catch (Exception e) { System.out.println(e.getMessage()); } } }} </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload