rdflib 查询 sparql 导致使用 FILTER 键解析错误
rdflib query sparql cause parsing error with FILTER key
我正在尝试 运行 使用 rdflib 对图进行 SPARQL 查询。如果我不使用 FILTER,它会很好地工作,否则它会导致在将字符串解析为查询时出错。 我正在使用 PYTHON 2.7。查看其他人的查询,我看不到任何语法错误。
这里查询:
query = " SELECT ?textspan WHERE " \
" { ?textspan rst:startOffset ?start ; " \
" rst:endOffset ?end . " \
" FILTER ( ?start <= "+denotedStartOffset+" < ?end ) } "
他们与:
query = " SELECT ?textspan WHERE " \
" { ?textspan rst:startOffset ?start ; " \
" rst:endOffset ?end . " \
" FILTER ( ?start <= 5 < ?end ) } "
错误:
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)
它说它不期望 'F' 所以它不识别 FILTER。
正如@UninformedUser 建议的那样,解决方案是 FILTER ( ?start <= 5 && 5 < ?end )
我正在尝试 运行 使用 rdflib 对图进行 SPARQL 查询。如果我不使用 FILTER,它会很好地工作,否则它会导致在将字符串解析为查询时出错。 我正在使用 PYTHON 2.7。查看其他人的查询,我看不到任何语法错误。 这里查询:
query = " SELECT ?textspan WHERE " \
" { ?textspan rst:startOffset ?start ; " \
" rst:endOffset ?end . " \
" FILTER ( ?start <= "+denotedStartOffset+" < ?end ) } "
他们与:
query = " SELECT ?textspan WHERE " \
" { ?textspan rst:startOffset ?start ; " \
" rst:endOffset ?end . " \
" FILTER ( ?start <= 5 < ?end ) } "
错误:
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)
它说它不期望 'F' 所以它不识别 FILTER。
正如@UninformedUser 建议的那样,解决方案是 FILTER ( ?start <= 5 && 5 < ?end )