Search code examples
sparql

How to get labels of subclasses of a specific class in SPARQL


Ontology Code I am new in Ontology development, I need to get labels of all subclasses of Link to Image of Ontology a specific class. I have already tried many queries but none of them working. If anyone can help me Thanks. I have already tried the following query

SELECT ?subject ?object
    WHERE { 
?subject rdfs:subClassOf?object.
filter regex (?object ,"CSProjects","i").
}

Solution

    1. If you want the labels, then you have to state that in your query.
    2. Classes are identified by a URI, thus, use the URI instead of a REGEX operation:
    SELECT ?cls ?clsLabel WHERE {
     ?cls rdfs:subClassOf <http://THE/URI/OF/YOUR/CLASS/CSProjects> ;
          rdfs:label ?clsLabel
    }
    

    Note, this will only return the explicitly asserted subclasses if no reasoning is enabled in the SPARQL engine.