Hi Romain, all! I looked into this, and have come up with a fix (commited on trunk as rev 1240). I also added your code as a test (specifically for bound, in "test/sparql_filter_bound.py").
However, this made me a little unconfortable. It was the second problem I've encountered that stems from the change in Variable.py to no longer keep its prefixing "?" internally. It seems the bindings dict in "rdflib/sparql/sparqlOperators.py" for bound (and other functions) contains Variable instances. My fix was *not* to add e.g. an __eq__ method to Variable with logic for this (allowing "?", and "$" too, possibly, since sparql allows this - not n3 though?). I am not sure of the effects of doing that in other places. (Also, I believe it is correct to keep the *name* and not any sigil in Variable, so I'm not opposed to that change in itself.) Instead I changed, in "sparqlOperators.py", this function: def __getQueryString(v) : if isinstance(v,Variable) : return v elif queryString(v) : return v else : return None into: def __getVariableName(v): if isinstance(v, Variable): return v elif queryString(v): return v[1:] else: return None (and replaced all uses in the same file accordingly). This since queryString already checks for the leading "?", so this was least invasive and works. I fear that this entire variable thing may be frail though, and that it would be sound to investigate if we could normalize this all over the code base. Good starting points: search for imports of "rdflib.sparql._questChar", the use of "[1:]" and "?". (On a related note, we should reasonably round up the different sparql tests and normalize plus complete them. There is a bunch of these "one-offs" right now. And in any event, many of these have regressed since 2.4.0. As noted, changing rdflib.sparql.Algebra.DAWG_DATASET_COMPLIANCE to False makes many of them succeed, so that's a good place to start looking.) Best regards, Niklas On 7/27/07, Romain Chantereau <[EMAIL PROTECTED]> wrote: > Hi ! > > It seems that there is a bug with the rdflib 2.4.0 sparql query, here an > code example inspired from > http://www.w3.org/TR/rdf-sparql-query/#func-bound : > > from rdflib import Literal, ConjunctiveGraph, Namespace, BNode, URIRef > > DC = Namespace(u"http://purl.org/dc/elements/1.1/") > FOAF = Namespace(u"http://xmlns.com/foaf/0.1/") > > graph = ConjunctiveGraph() > s = BNode() > graph.add((s, FOAF['givenName'], Literal('Alice'))) > b = BNode() > graph.add((b, FOAF['givenName'], Literal('Bob'))) > graph.add((b, DC['date'], Literal("2005-04-04T04:04:04Z"))) > > print graph.query("""PREFIX foaf: <http://xmlns.com/foaf/0.1/> > PREFIX dc: <http://purl.org/dc/elements/1.1/> > PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> > SELECT ?name > WHERE { ?x foaf:givenName ?name . > OPTIONAL { ?x dc:date ?date } . > FILTER ( bound(?date) ) }""").serialize('python') > > I think the expected result is [Literal('Bob')], but the result I have > is []. > > Thanks for your really great job, > -- > Romain Chantereau <[EMAIL PROTECTED]> > > _______________________________________________ > Dev mailing list > Dev@rdflib.net > http://rdflib.net/mailman/listinfo/dev > _______________________________________________ Dev mailing list Dev@rdflib.net http://rdflib.net/mailman/listinfo/dev