I ran the following queries in SPARQL in Jena framework against an ontology ( The wasBornIn predicate is present in the ontology )
select ?p where
{
?s ?p ?o FILTER NOT EXISTS { ?s :wasBornIn ?o }
}
and
select ?p where
{
{ ?s ?p ?o } MINUS { ?s :wasBornIn ?o }
}
For the first query, I am getting the following errors :
null
Error: Lexical error at line 7, column 21. Encountered: " " (32), after : "NOT"
and
null
Error: Encountered "<EOF>" at line 5, column 16.
Was expecting:
"{" ...
For the second query, I am getting a similar error :
null
Error: Lexical error at line 5, column 38. Encountered: " " (32), after : "MINUS"
Both the queries seems to be correct and I've no idea why I am getting those errors.
You first and second queries (assuming that you've got the :
prefix defined) are legal. You can check with sparql.org's query validator. E.g., these are both legal:
prefix : <>
select ?p where
{
?s ?p ?o FILTER NOT EXISTS { ?s :wasBornIn ?o }
}
prefix : <>
select ?p where
{
{ ?s ?p ?o } MINUS { ?s :wasBornIn ?o }
}
However, there's something you're not showing us; you're mentioning that there's an error in line 7 (for the first) one, but the query you've shown doesn't have 7 lines. Not only that, I'm not sure how you could encounter an EOF at line 5, and then still have a line 7 to get another error. Perhaps there's something different about the code that's actually constructing the query. Maybe you've got something like this:
"?s ?p ?o" +
"FILTER NOT EXISTS { ?s :wasBornIn ?o }"
in which case you'd end up with
?s ?p ?oFILTER NOT EXISTS { … }
(i.e., with a variable named ?oFILTER
). Without seeing your code, though, this would be hard to diagnose. You could also be parsing the query incorrectly, somehow.