Sesame : how to remove the inference during querie

2019-07-18 19:59发布

I'm looking for a solution in order to "remove" the inference during a query launched on Sesame. I must use a "Native Java Store RDF Schema" repository and I have this query : I have an instance, a NamedIndividual, and I want the uri of the class whose instance it is :

    SELECT DISTINCT ?uri WHERE  {   
        <http://www.semanticweb.org/ontotest#myInstance> rdf:type ?uri .
        FILTER (?uri rdf:type owl:Class)         
    }

The problem is that I get severals URI (whom the good URI) instead of one because of the inference. I get the superclasses of the ontology then there is no link with the class of the instance. How to obtain the right result without change the repository ?

2条回答
走好不送
2楼-- · 2019-07-18 20:42

It sounds like you're trying to return the most specific class(es) of which some individual is an instance. ThomasFrancart's answer explains how to disable inference, but you might not want to do that, because you might need inference to infer the most specific instance. For instance, you might have a class hierarchy with the relationship

SeniorCitizen ⊑ Person
Person ⊓ hasAge some integer[>= 60] ⊑ SeniorCitizen

and the data:

John rdf:type Person
John hasAge 62

Then if you disable inference, you won't be able to know that John is a SeniorCitizen, even though it's a more specific class than Person. It sounds like you actually want to keep inference enabled, but to only return the most specific class(es). You can do that with a query like this:

select ?class where {
  :myInstance rdf:type ?class .
  filter not exists { 
    ?subclass rdfs:subClassOf* ?class .
    :myInstance rdf:type ?subclass .
    filter ( ?subclass != ?class )
  }
}

This says to find those values of ?class such that :myInstance is an element of ?class, but only where there's not ?subclass that's a subclass of ?class (other than ?class itself) to which :myInstance also belongs. Note that an instance can have multiple most specific classes though.

See:

查看更多
Summer. ? 凉城
3楼-- · 2019-07-18 20:45

Set the setIncludeInferred(false) on your Query object before executing it through the API to avoid using inferred statements.

查看更多
登录 后发表回答