I was just writing a complex query on DBpedia and it is time that we have a place to share them with the tag coolqueries
:
SELECT DISTINCT ?instance ?label ?comment GROUP_CONCAT(DISTINCT ?s,"|") as ?wikicategories GROUP_CONCAT(DISTINCT ?dbo,"|") as ?DBpediaOntology GROUP_CONCAT(DISTINCT ?other,"|") as ?otherTax {
FILTER (?cat = <http://dbpedia.org/resource/Category:Computing> ) .
#FILTER (?cat = <http://dbpedia.org/resource/Category:Electronics> ) .
#FILTER (?cat = <http://dbpedia.org/resource/Category:Engineering> ) .
# getting the instances and the en label
?instance dct:subject ?s .
?instance rdfs:label ?label . FILTER (lang(?label)="en") .
?instance rdfs:comment ?comment . # enable for en abstracts only FILTER (lang(?comment)="en") .
# DBpedia ontology
?instance rdf:type ?dbo . FILTER (?dbo LIKE <http://dbpedia.org/ontology/%>).
# other taxonomies
?instance rdf:type ?other . FILTER (! ?other LIKE <http://dbpedia.org/ontology/%>).
# going down the hierarchy
{?s skos:broader ?cat }
UNION
{?s skos:broader/skos:broader ?cat }
UNION
{?s skos:broader/skos:broader/skos:broader ?cat }
}
GROUP BY ?instance ?label ?comment
LIMIT 10000