How to get terminal leaves in Wikipedia root category
I only want to get the leaves of the wikipedia category, but don't know how. I can get all the leaves
SELECT ?subcat WHERE {
?subcat skos:broader* category:Buildings_and_structures_in_France_by_city .
}
This gives me all the intermediate leaves (such as Category: Buildings_and_structures_in_Antibes), but I only want to get the last / bottom leaves of the tree. Leaves that can no longer be split. How can i do this?
source to share
You should just filter out values ?subcat
that are not terminal:
select ?subcat where {
?subcat skos:broader* category:Buildings_and_structures_in_France_by_city .
filter not exists { [] skos:broader ?subcat }
}
However, when I run this, I am not getting any results. I do not know why. I would guess that this is one of the features of Virtuoso (SPARQL endpoint on DBpedia), but I'm not sure. However, we can write an equivalent query that counts the number of things each ? Subcat skos: wider than, and only selects those that are skos: wideer 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
source to share