gjhiggins/rdflib — Issue #92: SPARQL parsing problem with negative values
Author: gjhiggins
Created: 2011-10-19 01:18:35+00:00
State: open

Originally filed by stefano....@gmail.com on 2009-11-24T11:47:33

Hi all, and thanks for the great library.

>>> rdflib.__version__
'2.4.2'

I am having problems with the following code, obtained from test_not_equals.py

from rdflib.Namespace import Namespace
from rdflib import plugin,RDF,RDFS,URIRef, StringInputSource, Literal
from rdflib.Graph import Graph,ReadOnlyGraphAggregate,ConjunctiveGraph
import rdflib
import sys
from pprint import pprint

def testSPARQLNotEquals():
NS = u"http://example.org/"
graph = ConjunctiveGraph()
graph.parse(StringInputSource("""
@prefix : .
@prefix rdf: <%s> .
:foo rdf:value 1.
:bar rdf:value -2."""%RDF.RDFNS), format="n3")
rt = graph.query("""SELECT ?node
WHERE {
?node rdf:value ?val.
FILTER (?val < -1)
}""",
initNs={'rdf':RDF.RDFNS },

DEBUG=False)
for row in rt:
item = row[0]
print item
#assert item == URIRef("http://example.org/bar")

if __name__ == '__main__':
testSPARQLNotEquals()

Get this error:

Traceback (most recent call last):
File "test_not_equals.py", line 29, in ?
testSPARQLNotEquals()
File "test_not_equals.py", line 22, in testSPARQLNotEquals
DEBUG=False)
File
"/Users/sbo/Work/Programs/Experimental/rdflib/rdflib-2.4.2/test/Graph.py",
line 738, in query

File "build/bdist.macosx-10.6-i386/egg/rdflib/sparql/bison/Processor.py",
line 50, in query
File "build/bdist.macosx-10.6-i386/egg/rdflib/sparql/Algebra.py", line
312, in TopEvaluate
File "build/bdist.macosx-10.6-i386/egg/rdflib/sparql/Algebra.py", line
165, in ReduceToAlgebra
File
"build/bdist.macosx-10.6-i386/egg/rdflib/sparql/bison/SPARQLEvaluate.py",
line 318, in createSPARQLPConstraint
File "", line 0, in ?
TypeError: bad operand type for unary -

Can you propose workarounds, if it's a bug ?