Search code examples
sparqlgraphdb

Sparql get individuals from top class only


I feel like this has an obvious answer I'm missing, but here's the problem:

I have an ontology which has a class 'Class_N1', with a subclass 'Class_N2', which has a subclass 'Class_N3', which has a subclass 'Class_N4'

When I run this query:

SELECT ?entity
WHERE {
    ?entity rdf:type :Class_N1
}

I get individuals from the top class ('Class_N1') and from its subclass and respective subclasses.

Is there anyway to get results which belong only in the top/super class?


Solution

  • You have inferencing enabled. There are three options to disable inferencing:

    1. Choose the "No inference" ruleset when creating your repository (screenshot).

    2. Uncheck the >>-like icon in the query editor (screenshots).

    3. Use GraphDB pseudo-graphs:

      SELECT ?entity
      FROM <http://www.ontotext.com/explicit>
      WHERE { ?entity rdf:type :Class_N1 }