Search code examples
sparqlowljenaontologyrdflib

SPARQL Query not returning depth


I have the following SPARQL Query:

SELECT ?depthClass (count(?mid)-1 as ?depth)
WHERE {
        {
            SELECT ?root WHERE {
                ?root a owl:Class
                FILTER NOT EXISTS {
                    ?root rdfs:subClassOf ?superroot 
                    filter ( ?root != ?superroot )
                    }
            }
        }
  ?depthClass rdfs:subClassOf* ?mid .
  ?mid rdfs:subClassOf* ?root .
}
group by ?depthClass
order by ?depth

It is supposed to return the class and the depth of the given class depthClass. However, it does not return anything. I don't see any error in the query.


Solution

  • After debugging I noticed that, since I was using owlready2 rdflib implementation, it probably did not support ?root a owl:Class syntax, after changing it to ?root rdf:type owl:Class it started working!