2

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.

user1156544
  • 1,725
  • 2
  • 25
  • 51

1 Answers1

4

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

Community
  • 1
  • 1
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • I think you are missing an ":instance a ?subclass" inside the FILTER, is it possible? The problem with this solution is that for some reason it performs very badly in terms of time. Not acceptable in my situation – user1156544 Apr 14 '16 at 07:56
  • @user1156544 Yup, missed the "instance a subclass". I'm kind of surprised that this performs badly: you're already able to get the classes to wide the instance belongs, so that shouldn't be too much. Maybe looking for other possible classes is more expensive. The bad performance was with a fixed version that has the "instance a subclass" in the subquery, right? – Joshua Taylor Apr 14 '16 at 11:00
  • @user1156544 since you said that this doesn't work for you, I've reopened the question, since it seems like those other answers won't work for you. You might want to update the question with a bit of the performance issues that you run into with this approach though, else others night recommend the same solution. – Joshua Taylor Apr 14 '16 at 11:01
  • Thanks. I will do some more tests and get more specific results and edit the question. Yes, it was with the fixed version, otherwise I get no results. – user1156544 Apr 14 '16 at 11:19
  • What is the value of ```:instance``` here? Is it something like ```schema:Thing a ?class```, where ```schema:Thing``` is a resource of schema.org ontology. – NikSp Nov 06 '22 at 20:11
  • @NikSp It's just some instance that you're interested in. OP used `ex:myElement` -- I used `:instance`. – Joshua Taylor Nov 06 '22 at 23:52
  • @JoshuaTaylor I have a similar usecase here in this OP (https://stackoverflow.com/questions/74322174/access-subclassof-subclassof-level-using-forwardchainingrdfsinferencer-with-spar). I would really appreciate if you have a look. When I execute the snippet you provide I receive an empty result. While I actually want the subclasses of instance ```schema:Thing``` while using inference and reasoning. – NikSp Nov 07 '22 at 06:25