Class: SPARQL::Algebra::Operator::SameTerm

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

Overview

The SPARQL sameTerm operator.

Examples:

(prefix ((xsd: <http://www.w3.org/2001/XMLSchema#>)
         (: <http://example.org/things#>))
  (project (?x ?v)
    (filter (sameTerm ?v)
      (bgp (triple ?x :p ?v)))))

See Also:

Constant Summary

NAME =
:sameTerm

Constants inherited from Binary

Binary::ARITY

Constants inherited from SPARQL::Algebra::Operator

ARITY

Instance Attribute Summary

Attributes inherited from SPARQL::Algebra::Operator

#operands, #options

Instance Method Summary (collapse)

Methods included from Evaluatable

#evaluate, #memoize

Methods inherited from Binary

#initialize

Methods inherited from SPARQL::Algebra::Operator

arity, base_uri, #base_uri, base_uri=, #boolean, #constant?, #eql?, #evaluatable?, evaluate, #executable?, for, #initialize, #inspect, #operand, prefixes, #prefixes, prefixes=, #to_sse, #to_sxp, #variable?

Methods included from Expression

cast, #constant?, #evaluate, for, new, open, parse, #to_sse, #variable?

Constructor Details

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

Instance Method Details

- (RDF::Literal::Boolean) apply(term1, term2)

Returns true if the operands are the same RDF term; returns false otherwise.

Parameters:

Returns:

  • (RDF::Literal::Boolean)

    true or false

Raises:

  • (TypeError)

    if either operand is unbound



29
30
31
# File 'lib/sparql/algebra/operator/same_term.rb', line 29

def apply(term1, term2)
  RDF::Literal(term1.eql?(term2))
end

- (SPARQL::Algebra::Expression) optimize

Returns an optimized version of this expression.



37
38
39
40
41
42
43
# File 'lib/sparql/algebra/operator/same_term.rb', line 37

def optimize
  if operand(0).is_a?(Variable) && operand(0).eql?(operand(1))
    RDF::Literal::TRUE
  else
    super # @see Operator#optimize
  end
end