How can I get only the top-level classes of a dataset? The query below returns also the sub-classes (of the top level classes) which I do not need:
SELECT DISTINCT ?class
WHERE {
?s a ?class .
}
You can filter out any classes that have a subClassOf predicate, e.g.
SELECT DISTINCT ?class
WHERE {
?s a ?class .
FILTER NOT EXISTS { ?class rdfs:subClassOf ?parent . }
}