You can find the length of a path between two resources in SPARQL if there's a unique path between the resources. (This has been described in a number of places now; e.g., this answer to Calculate length of path between nodes?.) However, you cannot use that technique if there are multiple paths joining the endpoints, because it works by counting nodes on the path(s) between the resources, so if there are multiple paths, it won't be very useful.
In DBpedia, there could be lots of paths between any pair of resources, so it's rather hard to use that sort of metric. An alternative that you could use, though, is to find the closest common superclass, and use a metric based on that. That approach has been discussed in this answer to finding common superclass and length of path in class hierarchies.