如何获得Wikipedia根目录类别的末页 [英] How to get the terminal leaves of a Wikipedia root category
问题描述
我只想让叶子成为维基百科类别,但不确定如何。我可以通过选择所有的叶子
I want to get only the leaves a wikipedia category but not sure how. I can get all the leaves by
SELECT ?subcat WHERE {
?subcat skos:broader* category:Buildings_and_structures_in_France_by_city .
}
这给了我所有中间叶子(例如Category:Buildings_and_structures_in_Antibes),但我想要以获得树的最后/底部叶子。叶子不能再分裂了。我该怎么做?
This gives me all intermediate leaves (such as Category:Buildings_and_structures_in_Antibes) but I want to get just the last/bottom leaves of the tree. Leaves that can not be split anymore. How can I do this?
推荐答案
您应该能够简单地过滤出<不是终端离开的code>?subcat :
select ?subcat where {
?subcat skos:broader* category:Buildings_and_structures_in_France_by_city .
filter not exists { [] skos:broader ?subcat }
}
但是,当我运行该程序时,没有任何结果。我不确定为什么。我想这是Virtuoso(DBpedia上的SPARQL端点)的特质之一,但我不确定。但是,我们可以编写一个等效查询,计算每个?subcat 比 skos:broader 的事物数量,并仅选择 skos:broader的事物比没有:
However, when I run that, I get no results. I'm not sure why. I'd guess that it's one of the idiosyncrasies of Virtuoso (the SPARQL endpoint on DBpedia), but I'm not sure. However, we can write an equivalent query that counts the number of things that each ?subcat is skos:broader than, and selects only those that are skos:broader than none:
select distinct ?subcat where {
?subcat skos:broader* category:Buildings_and_structures_in_France_by_city .
optional { ?subsubcat skos:broader ?subcat }
}
group by ?subcat
having count(?subsubcat) = 0
这篇关于如何获得Wikipedia根目录类别的末页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!