0

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.

Ajay_C
  • 1
  • 1
  • given that you didn't show the data ... I guess, your mistake is forgetting that every class is subclass of `owl:Thing`. Try `filter ( ?root != ?superroot && ?superroot != owl:Thing )` - you should also start debugging your query by using parts of the query only. Like `SELECT ?root WHERE { ?root a owl:Class }` and so on and so furth – UninformedUser Oct 07 '20 at 13:20
  • by the way, computing the depth doesn't work if there are multiple paths between the same pair of classes – UninformedUser Oct 07 '20 at 13:22

1 Answers1

0

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!

Ajay_C
  • 1
  • 1