Class: SPARQL::Algebra::Operator::Adjust

Inherits:
Binary show all
Includes:
Evaluatable
Defined in:
lib/sparql/algebra/operator/adjust.rb

Overview

The SPARQL adjust operator.

[121] BuiltInCall ::= … | ‘ADJUST’ ‘(’ Expression ‘,’ Expression ‘)’

Examples:

SPARQL Grammar

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?id (ADJUST(?d, ?tz) AS ?adjusted) WHERE {
  VALUES (?id ?tz ?d) {
    (1 "-PT10H"^^xsd:dayTimeDuration "2002-03-07"^^xsd:date)
  }
}

SSE

(prefix ((xsd: <http://www.w3.org/2001/XMLSchema#>))
 (project (?id ?adjusted)
  (extend ((?adjusted (adjust ?d ?tz)))
   (table (vars ?id ?tz ?d)
    (row
     (?id 1)
     (?tz "-PT10H"^^xsd:dayTimeDuration)
     (?d "2002-03-07"^^xsd:date))))))

See Also:

Constant Summary collapse

NAME =
[:adjust]

Constants inherited from Binary

Binary::ARITY

Constants inherited from SPARQL::Algebra::Operator

ARITY, IsURI, URI

Constants included from Expression

Expression::PATTERN_PARENTS

Instance Attribute Summary

Attributes inherited from SPARQL::Algebra::Operator

#operands

Instance Method Summary collapse

Methods included from Evaluatable

#evaluate, #memoize, #replace_aggregate!, #replace_vars!

Methods inherited from Binary

#initialize

Methods inherited from SPARQL::Algebra::Operator

#aggregate?, arity, #base_uri, base_uri, base_uri=, #bind, #boolean, #constant?, #deep_dup, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #initialize, #inspect, #ndvars, #node?, #operand, #optimize, #optimize!, #parent, #parent=, #prefixes, prefixes, prefixes=, #rewrite, #to_binary, to_sparql, #to_sxp, #to_sxp_bin, #validate!, #variable?, #variables, #vars

Methods included from Expression

cast, #constant?, #evaluate, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

Constructor Details

This class inherits a constructor from SPARQL::Algebra::Operator::Binary

Instance Method Details

#apply(operand, duration, **options) ⇒ RDF::Literal

Returns the first operand adjusted by the dayTimeDuration of the second operand

Parameters:

  • operand (RDF::Literal::Temporal)

    the operand

  • duration (RDF::Literal, String)

    the dayTimeDuration or an empty string.

Returns:

  • (RDF::Literal)

    literal of same type

Raises:

  • (TypeError)

    if the operand is not a numeric value



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/sparql/algebra/operator/adjust.rb', line 42

def apply(operand, duration, **options)
  case operand
  when RDF::Literal::Temporal
    case duration
    when RDF::Literal::DayTimeDuration
      operand.adjust_to_timezone(duration)
    when RDF::Literal
      raise TypeError, "expected second operand to be an empty literal, but got #{duration.inspect}" unless duration.to_s.empty?
      operand.adjust_to_timezone(nil)
    else
      raise TypeError, "expected second operand to be an RDF::Literal::DayTimeDuration, but got #{duration.inspect}"
    end
  else
    raise TypeError, "expected first operand to be an RDF::Literal::Temporal, but got #{operand.inspect}"
  end
end

#to_sparql(**options) ⇒ String

Returns a partial SPARQL grammar for this operator.

Returns:

  • (String)


64
65
66
# File 'lib/sparql/algebra/operator/adjust.rb', line 64

def to_sparql(**options)
  "ADJUST(#{operands.to_sparql(delimiter: ', ', **options)})"
end