Reputation: 685
(especially @JeenBroekstra)
Using the following graphs, I've got this SPARQL query that currently works on a Sesame repository:
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT *
FROM <http://spinrdf.org/sp>
FROM <http://spinrdf.org/spl>
FROM <http://spinrdf.org/spin>
FROM <http://topbraid.org/examples/kennedysSPIN>
FROM <http://topbraid.org/examples/kennedys>
FROM NAMED <http://topbraid.org/examples/kennedys>
WHERE {
GRAPH <http://topbraid.org/examples/kennedys> {
?s ?p ?o .
} .
OPTIONAL {
FILTER (sameTerm(rdf:type, ?p)) .
?o rdfs:subClassOf+ ?supC .
} .
OPTIONAL {
FILTER (sameTerm(rdf:type, ?p) && NOT EXISTS { ?s a ?newSupC . }) .
?o rdfs:subClassOf+ ?newSupC .
} .
FILTER (bound(?newSupC)) .
}
Since both last optional patterns share some filter I figured I could merge them and I resulted to this query :
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT *
FROM <http://spinrdf.org/sp>
FROM <http://spinrdf.org/spl>
FROM <http://spinrdf.org/spin>
FROM <http://topbraid.org/examples/kennedysSPIN>
FROM <http://topbraid.org/examples/kennedys>
FROM NAMED <http://topbraid.org/examples/kennedys>
WHERE {
GRAPH <http://topbraid.org/examples/kennedys> {
?s ?p ?o .
} .
OPTIONAL {
FILTER (sameTerm(rdf:type, ?p)) .
?o rdfs:subClassOf+ ?supC .
OPTIONAL {
FILTER ( NOT EXISTS { ?s a ?supC . } ) .
BIND (?supC as ?newSupC)
} .
} .
FILTER (bound(?newSupC)) .
}
but when executing it, I get an empty resultset.
Thought to ask here before filing a bug request : could you tell me where the query is wrong or is this a bug in Sesame ?
Thanks in advance, Max.
EDIT : I of course put the FILTER (bound(?newSupC)) just to expose the failing pattern. On the global scape, I still need all results even with variable ?newSupC unbound.
EDIT : Here are more details about configuration I use: Except for named graph http://topbraid.org/examples/kennedys, I updated the graphs with RDFS entailment. The Sesame repository is a simple Native store without inference support.
Upvotes: 2
Views: 507
Reputation: 685
After thought I was sticking too much of trying to merge the two OPTIONAL pattern where the solution was much more direct :
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT *
FROM <http://spinrdf.org/sp>
FROM <http://spinrdf.org/spl>
FROM <http://spinrdf.org/spin>
FROM <http://topbraid.org/examples/kennedysSPIN>
FROM <http://topbraid.org/examples/kennedys>
FROM NAMED <http://topbraid.org/examples/kennedys>
WHERE {
GRAPH <http://topbraid.org/examples/kennedys> {
?s ?p ?o .
} .
OPTIONAL {
FILTER (sameTerm(rdf:type, ?p)) .
?o rdfs:subClassOf ?supC .
} .
BIND (IF(NOT EXISTS { ?s a ?supC . }, ?supC, ?__unbound__) as ?newSupC) .
}
Anyway thanks for you time and advice, guys. Max.
Upvotes: 3