RDFLib/rdflib — Issue #40: Sparql FILTER ( BOUND() ) does not perform as per spec
Author: gjhiggins
Created: 2012-02-20 08:31:11+00:00
State: open

stephen....@gmail.com, 2009-02-11T06:14:26.000Z

What steps will reproduce the problem?
1. Given this source code:
# See http://www.w3.org/TR/rdf-sparql-query/#func-bound

from rdflib.store import IOMemory
from rdflib.Graph import ConjunctiveGraph as Graph
from rdflib import URIRef
from StringIO import StringIO

n3 = StringIO('''
@prefix foaf: .
@prefix dc: .
@prefix xsd: .

_:a foaf:givenName "Alice".

_:b foaf:givenName "Bob" .
_:b dc:date "2005-04-04T04:04:04Z"^^xsd:dateTime .
''')

db = IOMemory.IOMemory()
graph = Graph(db, identifier=URIRef('#'))

graph.parse(n3, format='n3')

print list(graph.query("""
PREFIX foaf:
PREFIX dc:
PREFIX xsd:
SELECT ?name
WHERE { ?x foaf:givenName ?name .
OPTIONAL { ?x dc:date ?date } .
FILTER ( bound(?date) )
}
"""))

print list(graph.query("""
PREFIX foaf:
PREFIX dc:
SELECT ?name
WHERE { ?x foaf:givenName ?name .
OPTIONAL { ?x dc:date ?date } .
FILTER (!bound(?date)) }
"""))

2. The first print statement should have a single element, with
Literal("Bob") in it.

3. The second print statement should have a single element, with the
Literal("Alice") in it.

What is the expected output? What do you see instead?

The first print statement has no results. The second has both Alice and Bob
in it.

According to drewp on irc, svn head of rdflib has an empty result for both
cases. I am using 2.4.0.

Comment 1 by drewpca
rdflib head was r1461 when I ran the test that returned [] and [].

Comment 2 by stephen....@gmail.com
I have done a test manually using Joseki, and have established that that performs as
per the w3c specification.

Comment 3 by eik...@gmail.com

Comment 4 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.