user6369776 user6369776 - 2 months ago 7x
Java Question

retrieve owl file data using Jena

I have the following owl file and want to retrieve the related data to a given class.

<owl:Class rdf:about="">
<rdfs:subClassOf rdf:resource=""/>
<obo:IAO_11 rdf:datatype="">A def def def def.</obo:IAO_0000115>
<oboInOwl:hasDbXref rdf:datatype="">AA:006394</oboInOwl:hasDbXref>
<oboInOwl:hasExactSynonym rdf:datatype="">abcde</oboInOwl:hasExactSynonym>
<rdfs:label rdf:datatype="">ABCDEFG</rdfs:label>

For example I wanted to retrieve the subClassOf which should be DOID_11 without success using the following code:

//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");
} in , "");

ExtendedIterator <? > classes = inf.listClasses();
while (classes.hasNext()) {
OntClass essaClasse = (OntClass);

System.out.println("Classe: " + essaClasse.getLocalName());
for (Iterator <? > i = essaClasse.listSubClasses(); i.hasNext();) {

OntClass c = (OntClass);
System.out.print(" " + c.getLocalName() + "\n");
} // end for

I get just "DOID_0001" instead of "DOID_0001" and "DOID_11". I need also to get all of the other information such as "" and "


No, you are wrong. The statement in your ontology is

DOID_0001 rdfs:subClassOf DOID_11

That means, DOID_11 is the superclass of DOID_0001 not vice versa. And if you ask for all subclasses of DOID_0001, it's indeed only the class itself as trivial inference.


Statements for each class can be retrieved via

    StmtIterator stmtIterator = inf.listStatements(essaClasse, null, (RDFNode) null);
    while(stmtIterator.hasNext()) {
        Statement st =;
        Property p = st.getPredicate();
        RDFNode o = st.getObject();
        System.out.println(p + ":" + o);