user1156544
user1156544

Reputation: 1817

SPARQL - Get asserted class when reasoning is enabled

When reasoning is activated in a triplestore, the following query

SELECT ?classiri
WHERE {
    ex:myElement rdf:type ?classiri
}

will produce as a result:

owl:Thing
ex:Animal
ex:Human
ex:MaleHuman

Is there a way to get only the explicitly asserted axiom as result? (in this case, obviously ex:MaleHuman)

Note that reasoning cannot be turned off, amongst other reasons because the above is part of a more complex query that needs reasoning.

Upvotes: 2

Views: 255

Answers (1)

Joshua Taylor
Joshua Taylor

Reputation: 85913

You can't be sure that it's the actual asserted result versus an inferred one, but you can get the most specific instance with a query like:

select ?class {
  :instance a ?class
  filter not exists {
    ?subclass rdfs:subClassOf ?class .
    filter (?subclass != ?class)
  }
}

That says to get values of ?class such that there are no values of ?subclass (other than ?class itself) that are subclasses of ?class to which :instance also belongs.

Related

Upvotes: 4

Related Questions