SPARQL "ASK" query to check if object property exist between two classes (Not b/w individuals)

StackOverflow https://stackoverflow.com/questions/23086219

  •  04-07-2023
  •  | 
  •  

문제

I want to query, if certain ObjectPropery (OP) exist between two classes inside an OWL2 file. I'm using JENA API to construct the SPARQL queries.

What I have tried till now:

First I used the SELECT query to check the classes for a given OP:

  " { SELECT ?domain ?range WHERE {\n" +
        ":isManagedBy rdfs:domain ?domain; \n" +
        " rdfs:range ?range. \n } }"  +
                        "}";

Then I wrapped it with ASK query

" ASK WHERE { \n" +
     " { SELECT ?domain ?range WHERE {\n" +
        ":isManagedBy rdfs:domain ?domain; \n" +
         " rdfs:range ?range. \n } }"  +
    "}";

It seems to give me the answer, but I think, I'm mixing up so many things in this query:

My Goal: Is to query if certain fact exist inside the OWL file or not (Boolean Answer)

Eg: OWL Snippet

<owl:ObjectProperty rdf:ID="isManagedBy">
          <rdf:type rdf:resource="owl#FunctionalProperty" />
            <rdfs:domain rdf:resource="#FunctionManagement" />
            <rdfs:range rdf:resource="#SymposiumPlanner2013"/>
    </owl:ObjectProperty>   

What I would like to check: isManagedBy(FunctionManagement, SymposiumPlanner2013) exists or not.

도움이 되었습니까?

해결책

I think that the possible duplicate (How to query Classes with Object Property in Sparql) I linked may be close enough to answer your question, but there's no need to wrap a select query in an ask query here. You're asking about whether your data contains the triples:

:isManagedBy rdfs:domain :FunctionManagement .
:isManagedBy rdfs:range  :SymposiumPlanner2013 .

You just want a query that asks whether that data is present:

prefix :     <…>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
ask {
    :isManagedBy rdfs:domain :FunctionManagement .
    :isManagedBy rdfs:range  :SymposiumPlanner2013 .
}

You can even use some abbreviations to make that a bit more concise:

prefix :     <…>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
ask {
    :isManagedBy rdfs:domain :FunctionManagement ;
                 rdfs:range  :SymposiumPlanner2013 .
}

다른 팁

It seems to me that you want to get the domain and range for a certain property, and you want to verify that they match some other specific values. If that is the case, and given your sample data, your second query is correct.

One thing to note is that there seems to be a small bit of confusion between the idea of a predicate holding between two classes, and a predicate holding between two members of a class.

What your sample data indicates, is that if you see an instance of :isManagedBy, say in the triple :steve :isManagedBy :bill, then we can infer that :steve rdf:type :FunctionManagement and :bill rdf:type :SymposiumPlanner2013. This doesn't say anything about the classes themselves, only about the subject and object of instances of the property.

If you are trying to see if some property holds about the class, such as "all members of :FunctionManagement :isManagedBy some :SymposiumPlanner2013", then you would use an owl:minCardinality restriction to express that in your data. Your query would then change to reflect the constructs used in explaining it. Below is an example of a small ontology specifying that constraint.

<owl:ObjectProperty rdf:about="#isManagedBy"/>


<owl:Class rdf:about="#FunctionManagement">
    <rdfs:subClassOf>
        <owl:Restriction>
            <owl:onProperty rdf:resource="#isManagedBy"/>
            <owl:someValuesFrom rdf:resource="#SymposiumPlanner2013"/>
        </owl:Restriction>
    </rdfs:subClassOf>
</owl:Class>


<owl:Class rdf:about="#SymposiumPlanner2013"/>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top