Filter Evaluation
SPARQL provides a subset of the functions and operators defined by XQuery Operator Mapping. XQuery 1.0 section 2.2.3 Expression Processing describes the invocation of XPath functions. The following rules accommodate the differences in the data and execution models between XQuery and SPARQL:
- Unlike XPath/XQuery, SPARQL functions do not process node sequences. When interpreting the semantics of XPath functions, assume that each argument is a sequence of a single node.
- Functions invoked with an argument of the wrong type will produce a type error. Effective boolean value arguments (labeled "xsd:boolean (EBV)" in the operator mapping
table below), are coerced to
xsd:booleanusing the EBV rules in section 17.2.2. - Apart from BOUND, COALESCE, NOT EXISTS and EXISTS, all functions and operators operate on RDF Terms and will produce a type error if any arguments are unbound.
- Any expression other than logical-or (
||) or logical-and (&&) that encounters an error will produce that error. - A logical-or that encounters an error on only one branch will return TRUE if the other branch is TRUE and an error if the other branch is FALSE.
- A logical-and that encounters an error on only one branch will return an error if the other branch is TRUE and FALSE if the other branch is FALSE.
- A logical-or or logical-and that encounters errors on both branches will produce either of the errors.
The logical-and and logical-or truth table for true ( T ), false ( F ), and error ( E ) is as follows:
| A | B | A || B | A && B |
|---|---|---|---|
| T | T | T | T |
| T | F | T | F |
| F | T | T | F |
| F | F | F | F |
| T | E | T | E |
| E | T | T | E |
| F | E | E | F |
| E | F | E | F |
| E | E | E | E |
Invocation
SPARQL defines a syntax for invoking functions on a list of arguments. Unless otherwise noted, these are invoked as follows:
- Argument expressions are evaluated, producing argument values. The order of argument evaluation is not defined.
- Numeric arguments are promoted as necessary to fit the expected types for that function or operator.
- The function or operator is invoked on the argument values.
If any of these steps fails, the invocation generates an error. The effects of errors are defined in Filter Evaluation.
There are also "functional forms" which have different evaluation rules to functions as specified by each such form.
Effective Boolean Value (EBV)
Effective boolean value is used to calculate the arguments to the logical functions
logical-and, logical-or, and fn:not, as well as evaluate the result of a FILTER expression.
The XQuery Effective Boolean Value rules rely on the definition of XPath's fn:boolean. The following rules reflect the rules for fn:boolean applied to the argument types present in SPARQL queries:
- The EBV of any literal whose type is
xsd:booleanor numeric is false if the lexical form is not valid for that datatype (e.g. "abc"^^xsd:integer). - If the argument is a typed literal with a datatype of
xsd:boolean, and it has a valid lexical form, the EBV is the value of that argument. - If the argument is a plain literal or a typed literal with a datatype of
xsd:string, the EBV is false if the operand value has zero length; otherwise the EBV is true. - If the argument is a numeric type or a typed literal with a datatype derived from a numeric type, and it has a valid lexical form, the EBV is false if the operand value is NaN or is numerically equal to zero; otherwise the EBV is true.
- All other arguments, including unbound arguments, produce a type error.
An EBV of true is represented as a typed literal with a datatype of xsd:boolean and a lexical value of "true"; an EBV of false is represented as a typed literal
with a datatype of xsd:boolean and a lexical value of "false".
Copyright © 2013 W3C® (MIT, ERCIM, Keio, Beihang). This software or document includes material copied from or derived from SPARQL 1.1 Query.