RDFLib/rdflib — Issue #87: SPARQL parsing problem with negative values
Author: gjhiggins
Created: 2012-02-20 08:32:23+00:00
State: open

stefano....@gmail.com, 2009-11-24T11:47:33.000Z

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 ?

Comment 1 by eik...@gmail.com

Comment 2 by eik...@gmail.com

Comment 3 by eik...@gmail.com
These issues involve bits that have been moved out of rdflib proper for now. We will re-open them
or move them to rdfextas as appropriate.