Home > Blockchain >  SPARQL Query - get top-level classes of a dataset
SPARQL Query - get top-level classes of a dataset

Time:01-29

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 .
}

CodePudding user response:

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 . } 
}
  •  Tags:  
  • Related