I'm trying to run a SPARQL query against a graph with rdflib. It works well if i didn't use FILTER else it cause error on parsing the string to a query. i'm using PYTHON 2.7. Looking at other people query i cannot see any syntax error. Here the query:
query = " SELECT ?textspan WHERE " \
" { ?textspan rst:startOffset ?start ; " \
" rst:endOffset ?end . " \
" FILTER ( ?start <= "+denotedStartOffset+" < ?end ) } "
they same with:
query = " SELECT ?textspan WHERE " \
" { ?textspan rst:startOffset ?start ; " \
" rst:endOffset ?end . " \
" FILTER ( ?start <= 5 < ?end ) } "
The error:
Traceback (most recent call last):
File "link.py", line 27, in <module>
qres = g.query(QUERY_2)
File "/usr/local/lib/python2.7/dist-packages/rdflib/graph.py", line 1085, in query
query_object, initBindings, initNs, **kwargs))
File "/usr/local/lib/python2.7/dist-packages/rdflib/plugins/sparql/processor.py", line 74, in query
parsetree = parseQuery(strOrQuery)
File "/usr/local/lib/python2.7/dist-packages/rdflib/plugins/sparql/parser.py", line 1058, in parseQuery
return Query.parseString(q, parseAll=True)
File "/usr/local/lib/python2.7/dist-packages/pyparsing.py", line 1947, in parseString
raise exc
pyparsing.ParseException: Expected {SelectQuery | ConstructQuery | DescribeQuery | AskQuery}, found u'F' (at char 103), (line:1, col:104)
It says it doesn't expect 'F' so it doesn't recognize FILTER.
As @UninformedUser suggest the solution was FILTER ( ?start <= 5 && 5 < ?end )