Two more failing SPARQL query test cases: is it me or is it the SPARQL library?

24 views
Skip to first unread message

Graham Klyne

unread,
Apr 26, 2013, 5:47:34 AM4/26/13
to rdfli...@googlegroups.com
Two queries I'm trying to use are not working as expected:

(1)         ASK { :s1 :p1 ?value . FILTER ( str(xsd:integer(?value)) ) }

and

(2)        SELECT * WHERE
            {
              ?s a :test .
              OPTIONAL { ?s rdfs:label ?label }
              OPTIONAL { filter(!bound(?label)) BIND(str(?s) as ?label) }
            }

...


I'm using forks of rdflib and rdflib-sparql with minor changes (reflecting earlier reports):


(I propose to offer these as pull requests when I have my tests sorted.)

...

Query (1) (https://github.com/wf4ever/ro-manager/blob/minim-eval/src/spike/TestSparqlQueries.py#L109) above is attempting to check that a plain literal contains a string that conforms with the permitted lexical space of xsd:integer.  Reading the SPARQL spec, I /think/ it should work:

        # "FILTERs eliminate any solutions that, when substituted into the expression, 
        # either result in an effective boolean value of false or produce an error" 
        #
        # Further, the str() of any valid integer is a non-blank string, which in SPARQL
        # yields an equivalent boolean value (EBV) of True.
        # Thus, only valid integer literals should be accepted.

but others may see this differently.  In this case, I have a fallback to use a regex filter that does seem to work.

...

Query (2) (https://github.com/wf4ever/ro-manager/blob/minim-eval/src/spike/TestSparqlQueries.py#L164) is an attempt to create a query that returns a default label if one is not explicitly provided.  Currently, my workaround it to add extra code in the query response handler, but part of the purpose of my work here is to see how much of such code can be handled within SPARQL.  Again, I think it should work, but others may disagree.

I also tried the bind(...) without the filter, thinking that attempting to rebind would block the second optional part.  I also tried using a UNION expression to achieve the same result, but that didn't work for me.

#g


Gunnar Aastrand Grimnes

unread,
Apr 26, 2013, 8:26:35 AM4/26/13
to rdfli...@googlegroups.com
These ones were the SPARQL engine :)

Fixed in:

https://github.com/RDFLib/rdflib/commit/25cf484d017ef1c3b2277722cc2ea314a69b7dd3
and
https://github.com/RDFLib/rdflib/commit/5cd53fa35e105881ccd6f8a2f2ca615d4b9c3d38

> I'm using forks of rdflib and rdflib-sparql with minor changes (reflecting earlier reports):

I've added the fix for str keys to FrozenDict.

Note that for rdflib 4 we will roll the sparql engine back into core,
so I've fixed everything in the "reunification" branch of rdflib now:

https://github.com/RDFLib/rdflib/tree/reunification

details below.

>
> (1) ASK { :s1 :p1 ?value . FILTER ( str(xsd:integer(?value)) ) }


The problem was that the STR builtin did not propegate errors, instead
it just made a string out of the error message.

>
> and
>
> (2) SELECT * WHERE
> {
> ?s a :test .
> OPTIONAL { ?s rdfs:label ?label }
> OPTIONAL { filter(!bound(?label)) BIND(str(?s) as ?label) }
> }

This one was trickier. There was a bug in the algebra generation - the
BIND didn't see the value of ?s
It was a bug, in the process of fixing I also came of the perhaps
clearer query :

SELECT ?s (COALESCE(?reallabel, ?genlabel) AS ?label) WHERE
{
?s a :test .
BIND(str(?s) as ?label)
OPTIONAL { ?s rdfs:label ?reallabel }

}

Your query also works, although only with the second optional (the
?label from the first optional is not visible when the second is
executed, this may also be a bug :)

--
http://gromgull.net
Reply all
Reply to author
Forward
0 new messages