qootec
qootec

Reputation: 511

Order of bind/optional

Using GraphDB, I see the following behavior in an OWL2-RL optimized repo. Probably I’m doing something wrong... but I fail to see what. Probably not specific to GraphDB, but generic SPARQL question.

Full repo contents:

PREFIX owl: http://www.w3.org/2002/07/owl#
PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema#
PREFIX xsd: http://www.w3.org/2001/XMLSchema#
PREFIX : https://testontology#
insert data {
    graph <https://graph/ontology> {
        :objectProp1 a owl:ObjectProperty;
            rdfs:range owl:Thing;
            :ingestionName "objectProp1".
        :objectProp2 a owl:ObjectProperty;
            rdfs:range owl:Thing;
            :ingestionName "objectProp2".
        :dataProp1 a owl:DatatypeProperty;
            rdfs:range owl:Thing;
            :ingestionName "dataProp1".
        :dataProp2 a owl:DatatypeProperty;
            rdfs:range owl:Thing;
            :ingestionName "dataProp2".
    }
}

Query (I'm not suggesting this is a good query approach, just trying to get it explained...):

PREFIX : https://testontology#
PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema#
PREFIX owl: http://www.w3.org/2002/07/owl#
PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
select * where {
    ?propertyIRI :ingestionName ?ingestionName.

    optional {
        ?propertyIRI a owl:DatatypeProperty.
        BIND( "ABC" as ?isDataProp_flag )
    }
    BIND(BOUND(?isDataProp_flag) as ?isDataProp)
}

Response:

Result table

Question: I don’t understand result row 3… The isDataProp_flag has some value, so BOUND should return true, no?

When requesting GraphDB's query plan, I see the BIND statement has been moved:

GraphDB query plan

Questions:

For clarity, a more appropriate way to obtain the same would be:

PREFIX : https://testontology#
PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema#
PREFIX owl: http://www.w3.org/2002/07/owl#
PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
select ?propertyIRI ?isDataProp where {
    ?propertyIRI :ingestionName ?ingestionName.
    BIND(EXISTS {?propertyIRI a owl:DatatypeProperty} as ?isDataProp)
}

The latter query works as expected.

Upvotes: 2

Views: 47

Answers (0)

Related Questions