Is it possible to get all classes and their respective instances using a single SPARQL query?

136 views Asked by At

I have a requirement to show all the classes and their respective instances when the user accesses our website. We use Allegrograph as our RDF database. So once the user selects the repository from which to fetch the data, we need to show all the classes and their respective instances present in the entire repository. SO is it possible to achieve this through a single SPARQL query?

I know the below SPARQL will fetch all the classes,

SELECT DISTINCT ?class
WHERE {
  ?s a ?class .
}

But how do i get all the instances for each class that the above SPARQL query returns? I need to know if it is possible in a single SPARQL query. Your help is much appreciated as it is crucial for our project.

1

There are 1 answers

0
AndyS On
SELECT ?s ?class WHERE  { ?s a ?class }