问题
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.
回答1:
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)
来源:https://stackoverflow.com/questions/31614043/find-superclasses-and-sort-by-distance-in-sparql