gjhiggins/rdflib — Issue #41: Sparql FILTER ( BOUND() ) does not perform as per spec
Author: gjhiggins
Created: 2011-10-19 01:02:45+00:00
State: open

Originally filed by stephen....@gmail.com on 2009-02-11T06:14:26

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.