Find superclasses and sort by distance in SPARQL

冷暖自知 提交于 2021-01-29 02:13:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!