SPARQL Query Question
Hi All,
I'm using SPARQL with JFS Query and Indexing and I have a question about forming a SPARQL query. I
want to have a query that reports results that not only match a criteria, but are also missing a
field. For example, I might have an index that generates something like this:
<j>813f9e12-bbee-4013-a593-eeab8ccd08fc</j>
So my query would like (ignoring the PREFIX declarations) like this:
SELECT ?resource WHERE { ?resource j.2:poolId \"813f9e12-bbee-4013-a593-eeab8ccd08fc\" ;
j.2:commandLocator \"\" . }
However, that would not match, because there is no j.2:commandLocator in the index. I do want it to
match when the poolId is a certain value and there no entry for commandLocator in the index (because
there is no commandLocator). How can I do the second part?
Thanks in advance!
--Stephen
I'm using SPARQL with JFS Query and Indexing and I have a question about forming a SPARQL query. I
want to have a query that reports results that not only match a criteria, but are also missing a
field. For example, I might have an index that generates something like this:
<j>813f9e12-bbee-4013-a593-eeab8ccd08fc</j>
So my query would like (ignoring the PREFIX declarations) like this:
SELECT ?resource WHERE { ?resource j.2:poolId \"813f9e12-bbee-4013-a593-eeab8ccd08fc\" ;
j.2:commandLocator \"\" . }
However, that would not match, because there is no j.2:commandLocator in the index. I do want it to
match when the poolId is a certain value and there no entry for commandLocator in the index (because
there is no commandLocator). How can I do the second part?
Thanks in advance!
--Stephen
One answer
Yes this is feasible using the bound Sparql function combined with OPTIONAL, see http://www.w3.org/TR/rdf-sparql-query/#func-bound for full details, but roughly you could write your query like:
SELECT ?resource
WHERE {
?resource j.2:poolId "813f9e12-bbee-4013-a593-eeab8ccd08fc" .
OPTIONAL { ?resource j.2:commandLocator ?loc } .
FILTER ( !bound(?loc) )
}