Questions on evaluation of unbound variables.

I was looking for the references that told me what to do when an
unbound variable appears in a FILTER expression but I've been having
trouble with locating them.  Maybe you can point me at the right
places.


RDF Data (data.rdf) - the empty graph:
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
</rdf:RDF>


Query 1: optional test
PREFIX ex: <http://example.org/>
SELECT ?s
FROM <data.rdf>
WHERE {
  OPTIONAL { ex:a ex:b ?s }
}

The answer to this is a well defined result set with 1 answer:
  ?s=unbound


Query 2: BOUND test
PREFIX ex: <http://example.org/>
SELECT ?s
FROM <data.rdf>
WHERE {
  OPTIONAL { ex:a ex:b ?s }
  FILTER BOUND(?s)
}

This also has well defined answer - the empty result set - since
BOUND takes a variable type argument and can check for variable
boundness.


Query 3: unbound variable
PREFIX ex: <http://example.org/>
SELECT ?s
FROM <data.rdf>
WHERE {
  OPTIONAL { ex:a ex:b ?s }
  FILTER (?s)
}

What result should this give?

My analysis: ?s is evaluated acording to Sec 11: Testing Values
http://www.w3.org/TR/2006/CR-rdf-sparql-query-20060406/#tests
which describes this as evaluating an expression; here that is ?s
it says:
  [[FILTERs eliminate any solutions that, when substituted into the
  expression, result in either an effective boolean value of false or
  produce an error. ]]

Does ?s with no binding for s evaluate to false or error?
Is this a type error or another kind of error?

I couldn't find a section in the document to answer this.

The result set is the same in either case here but may not in other
cases.  If the result is error, it may allow shortcutting some
expression evaluation since the error value will propogate e.g
in arithmetic expressions like
  ?s / foo:bar(....)
where foo:bar is something expensive to compute
it need not be evaluated if ?s returns an error


Query 4: unbound variable in expression evaluation
PREFIX ex: <http://example.org/>
SELECT ?s
FROM <data.rdf>
WHERE {
  OPTIONAL { ex:a ex:b ?s }
  FILTER (?s = FALSE)
}

Depending on the answer to the question above, this filter expression
will return Error if unbound ?s evaluates to Error or True if unbound
?s evaluates to False.

Which means different numbers of results will be given, either none or 1.
So this query is a test for how current implementations evaluate
this.

My reasoning for this is based on the T,F,E table in
  http://www.w3.org/TR/2006/CR-rdf-sparql-query-20060406/#evaluation
and
  [[Any expression other than logical or (||) or logical and (&&) that
   encounters an error will produce that error. ]]
  -- ibid
which applies here to the equal(=) function.


Can you pass an unbound variable to an (extension) function?  I'm
guessing not since
  http://www.w3.org/TR/2006/CR-rdf-sparql-query-20060406/#extensionFunctions
says the arguments are RDF terms.


Query 5: unbound variable in an extension function
PREFIX ex: <http://example.org/>
PREFIX foo: <http://example.org/foo#>

SELECT ?s
FROM <data.rdf>
WHERE {
  OPTIONAL { ex:a ex:b ?s }
  FILTER foo:bar(?s)
}

What does this return?

Does it do this without evaluating the extension function?


This issue applies to Constructor Functions evaluating over undefined
variables, which are defined in a different section:
http://www.w3.org/TR/2006/CR-rdf-sparql-query-20060406/#FunctionMapping


Query 6: unbound variable in constructor function

PREFIX ex: <http://example.org/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?s
FROM <data.rdf>
WHERE {
  OPTIONAL { ex:a ex:b ?s }
  FILTER (xsd:decimal(?s) = 0)
}

What does this return?

(using casting defined in
http://www.w3.org/TR/xpath-functions/#casting-to-numerics
)

---

While checking these I found ARQ evaluates unbound ?s to Error, not
False so that the answers to queries 3-6 are all the empty set.  I
didn't test query 5 without having an extension function handy to use.

Dave

Received on Saturday, 1 July 2006 23:03:27 UTC