# File 'lib/sparql/algebra/operator.rb', line 370defboolean(literal)caseliteralwhenFalseClassthenRDF::Literal::FALSEwhenTrueClassthenRDF::Literal::TRUE# If the argument is a typed literal with a datatype of
# `xsd:boolean`, the EBV is the value of that argument.
# However, the EBV of any literal whose type is `xsd:boolean` is
# false if the lexical form is not valid for that datatype.
whenRDF::Literal::BooleanRDF::Literal(literal.valid?&&literal.true?)# If the argument is a numeric type or a typed literal with a
# datatype derived from a numeric type, the EBV is false if the
# operand value is NaN or is numerically equal to zero; otherwise
# the EBV is true.
# However, the EBV of any literal whose type is numeric is
# false if the lexical form is not valid for that datatype.
whenRDF::Literal::NumericRDF::Literal(literal.valid?&&!(literal.zero?)&&!(literal.respond_to?(:nan?)&&literal.nan?))# 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.
elsecasewhenliteral.is_a?(RDF::Literal)&&(literal.plain?||literal.datatype.eql?(RDF::XSD.string))RDF::Literal(!(literal.value.empty?))# All other arguments, including unbound arguments, produce a type error.
elseraiseTypeError,"could not coerce #{literal.inspect} to an RDF::Literal::Boolean"endendend

For constant expressions containing no variables, returns the result
of evaluating the expression with empty bindings; otherwise returns
self.

Optimization is not possible if the expression raises an exception,
such as a TypeError or ZeroDivisionError, which must be conserved
at runtime.

311
312
313
314
315
316
317
318
319

# File 'lib/sparql/algebra/operator.rb', line 311defoptimizeifconstant?# Note that if evaluation results in a `TypeError` or other error,
# we must return `self` so that the error is conserved at runtime:
evaluaterescueselfelsesuper# returns `self`
endend