I'm looking for a SPARQL query that could return the position of specified subclass in the OWL hierarchy. I have studied several examples but the best result I could ever reach is the computation the relative paths between the specified superclass and its subclasses (thanks to Joshua Taylor). Instead of that I need to calculate the "absolute" depth for a given subclass.
My ontology contains several top-level classes and every of them is followed with a separate tree of subclasses. Here is part of my OWL (converted to TTL with a rdfcat utility):
@prefix : <http://www.semanticweb.org/administrator/ontologies/2014/7/untitled-ontology-9#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
:depression a owl:Class ;
rdfs:subClassOf :pit .
:pit a owl:Class ;
rdfs:subClassOf :on_the_road .
:on_the_road a owl:Class ;
rdfs:subClassOf :traffic_accident .
:traffic_accident a owl:Class .
In this case for a given depression
class I expect to get 3, pit
-> 2, on_the_road
-> 1, traffc_accident
(a top-level class) -> 0.