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

Inherits:
Operator::Binary
  • Object
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]

Instance Method Summary collapse

Methods included from Evaluatable

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

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