You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Bumper Guard <ba...@hotmail.de> on 2013/10/27 11:11:19 UTC

Re: Problem with finding superclasses

Greetings!

I want to list all superclasses of a class using the 
listSuperClasses()-Method of OntClass. For most classes that's not a 
problem, but in some special cases I just receive a null as a 
superclass. For example I've got this ontology:

...
     <!-- [..]#Student -->

     <Class rdf:about="[..]#Student">
         <rdfs:subClassOf rdf:resource="[..]#Person"/>
         <rdfs:subClassOf>
             <Class>
                 <unionOf rdf:parseType="Collection">
                     <rdf:Description rdf:about="[..]#Man"/>
                     <rdf:Description rdf:about="[..]#Woman"/>
                 </unionOf>
             </Class>
         </rdfs:subClassOf>
     </Class>
...

The [..] are just to shorten the ontology reference which is definitely 
correct. The Person is recognized without any problem, but whenever the 
ontology contains a "<rdfs:subClassOf> ... </rdfs:subClassOf>", it won't 
find the superclass and returns null instead (ontClass.hasSuperClass() 
returns true though). There are not only unions but also restrictions in 
this form, that can't be found.

How can I correctly read these superclasses, whenever I receive a null?

Thanks in advance!

Re: Problem with finding superclasses

Posted by Dave Reynolds <da...@gmail.com>.
On 27/10/13 10:11, Bumper Guard wrote:
> Greetings!
>
> I want to list all superclasses of a class using the
> listSuperClasses()-Method of OntClass. For most classes that's not a
> problem, but in some special cases I just receive a null as a
> superclass. For example I've got this ontology:
>
> ...
>      <!-- [..]#Student -->
>
>      <Class rdf:about="[..]#Student">
>          <rdfs:subClassOf rdf:resource="[..]#Person"/>
>          <rdfs:subClassOf>
>              <Class>
>                  <unionOf rdf:parseType="Collection">
>                      <rdf:Description rdf:about="[..]#Man"/>
>                      <rdf:Description rdf:about="[..]#Woman"/>
>                  </unionOf>
>              </Class>
>          </rdfs:subClassOf>
>      </Class>
> ...
>
> The [..] are just to shorten the ontology reference which is definitely
> correct. The Person is recognized without any problem, but whenever the
> ontology contains a "<rdfs:subClassOf> ... </rdfs:subClassOf>", it won't
> find the superclass and returns null instead (ontClass.hasSuperClass()
> returns true though). There are not only unions but also restrictions in
> this form, that can't be found.
>
> How can I correctly read these superclasses, whenever I receive a null?

Without seeing your code it is hard to be sure what you mean by "null".

Those classes (unions, restrictions) are anonymous (i.e. they are bNodes 
and have no URI). listSuperClasses will return an OntClass for those 
just fine and you can then use methods like isUnionClass, isRestriction 
etc to understand what class you have and then asUnionClass etc to get 
convenience methods to access the information on those classes.

You may be seeing "null" as a result of doing something like getURI or 
getLocalName. Since those resources have no URI such methods should 
return null.

Somewhere there is an example showing how to traverse a class hierarchy 
using the Ont API which clarifies this but I can't find it in the new 
web site layout.

Dave