I have tried a similar query and also got a parsing exception. I have gone through rdflib's SPARQL parser code and it doesn't seem to exist a rule to handle IN
or NOT IN
. I would assume that this functionality is not implemented.
Anyway, I am not sure you are using it correctly. Having a look at the NOT IN
definition in the SPARQL 1.1 spec ... it defines the IN
operator to be used against a list of expressions. Therefore, you'd do:
FILTER (?item NOT IN (?SetB))
And I am not completely sure if you can use variables in the right-hand side because all the examples in the spec use terms. edit: see RobV message , it's possible to use variables in the RLH
workaround with one query
One possible solution, that might work for you is to use OPTIONAL
and bound
(both supported in rdflib). Something like ...
SELECT ?title WHERE {
some logic defining ?item
OPTIONAL {
some logic defining ?SetB
}
FILTER (bound(?SetB) && ?setB != ?item)
}
Without knowing more about your query I cannot advice better with this case.
workaround with two queries
The easiest way to solve this with rdlib is to use filters and two queries, the first query retrieves all the posible values for ?SetB
. Ant in the second query you dynamically create
a filter:
SELECT ?title WHERE {
some logic defining ?item
FILTER (?item != <setb_val1> && ?item != <setb_val2> &&
... && ?item != <setb_val2>)
}