1

I'm finding all the superclasses of a type, and all the superclasses of that type, and so on all the way up. I'm doing this using the + operator:

SELECT ?superclass WHERE{
    <myType> <superclassPredicate>+ ?superclass
}

I would like to get these superclasses back in a reasonable order (eg most specific to least specific). Is there a way to guarantee this? I'm familiar with ORDER BY, but I'm not sure what to put into it.

To put it another way: can I keep track of how many "jumps" are made by the + operator?

EDIT

It does seems to do this by itself (at least in my implementation), but I'd like to know if this is always the case.

Sawbones
  • 113
  • 4
  • Have you looked for existing answers? As far as I remember, there are very related questions that have been answered, e.g. if you look for answers by @Joshua Taylor – UninformedUser Jul 25 '15 at 01:31

1 Answers1

0

You can take the following part of @Joshua Taylor's answer here to sort by the number of classes inbetween:

prefix : <http://example.org/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select ?class where { 
  :Win7 rdfs:subClassOf* ?mid .
  ?mid rdfs:subClassOf* ?class .
}
group by ?class
order by count(?mid)

(@Joshua Taylor)

Community
  • 1
  • 1
Spork
  • 1,631
  • 1
  • 21
  • 37