Class: SPARQL::Algebra::Operator::Datatype

Inherits:
Unary show all
Defined in:
lib/sparql/algebra/operator/datatype.rb

Overview

The SPARQL datatype operator.

See Also:

Constant Summary

NAME =
:datatype

Constants inherited from Unary

ARITY

Instance Method Summary (collapse)

Methods inherited from Unary

#initialize

Methods inherited from SPARQL::Algebra::Operator

#boolean, #constant?, evaluate, #initialize, #operand, #to_sse, #variable?

Constructor Details

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

Instance Method Details

- (RDF::URI) evaluate(solution)

Returns the datatype IRI of the operand.

If the operand is a simple literal, returns a datatype of xsd:string.

Parameters:

  • (RDF::Query::Solution) solution

Returns:

  • (RDF::URI)

    the datatype IRI, or xsd:string for simple literals

Raises:

  • (TypeError)

    if the operand is not a typed or simple RDF::Literal



19
20
21
22
23
24
25
26
27
28
# File 'lib/sparql/algebra/operator/datatype.rb', line 19

def evaluate(solution)
  case literal = operand(0, solution)
    when RDF::Literal then case
      when literal.typed?  then RDF::URI(literal.datatype)
      when literal.simple? then RDF::XSD.string
      else raise TypeError, "expected a typed or simple RDF::Literal, but got #{literal.inspect}"
    end
    else raise TypeError, "expected an RDF::Literal, but got #{literal.inspect}"
  end
end