Search code examples
sparqlprotege4

SPARQL query on Protege for Number of Classes


In order to determine the number of classes in a .owl file,

I was advised to use the following SPARQL query:

SELECT ( count(?class) as ?count )
    WHERE { graph <put_your_model_graph_name_here> { ?class a owl:Class . } }

However, when I replace the put_your_model_graph_name_here with my ontology IRI, I get 0

I also tried http://blahblahblah followed immediately by # to no avail.

What am I doing wrong?


Solution

  • Difficult to tell without seeing how you are loading and querying the data. Try using:

    SELECT ( count(?class) as ?count ) { ?class a owl:Class }
    

    which will query the default graph, or

    SELECT ?g ( count(?class) as ?count ) 
    { graph ?g { ?class a owl:Class } }
    group by ?g
    

    which will give counts for all the named graphs.