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

Inherits:
Binary show all
Includes:
Evaluatable
Defined in:
vendor/bundler/ruby/2.7.0/bundler/gems/sparql-8509b1578e69/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:

Direct Known Subclasses

RDF::N3::Algebra::Log::NotEqualTo

Constant Summary collapse

NAME =
:sameTerm

Constants inherited from Binary

Binary::ARITY

Constants inherited from SPARQL::Algebra::Operator

ARITY, IsURI, URI

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, #formulae, #initialize, #inspect, #ndvars, #node?, #operand, #optimize!, #parent, #parent=, prefixes, #prefixes, prefixes=, #rewrite, #to_binary, #to_sxp, #to_sxp_bin, #validate!, #variable?, #vars

Methods included from Expression

cast, #constant?, #evaluate, extension, extensions, for, #invalid?, new, #node?, open, #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(term1, term2) ⇒ RDF::Literal::Boolean

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

Parameters:

Returns:

Raises:

  • (TypeError)

    if either operand is unbound



29
30
31
# File 'vendor/bundler/ruby/2.7.0/bundler/gems/sparql-8509b1578e69/lib/sparql/algebra/operator/same_term.rb', line 29

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

#optimize(**options) ⇒ SameTerm

Returns an optimized version of this expression.

Return true if variable operand1 is a bound variable and equals operand2

Returns:

See Also:



40
41
42
43
44
45
46
# File 'vendor/bundler/ruby/2.7.0/bundler/gems/sparql-8509b1578e69/lib/sparql/algebra/operator/same_term.rb', line 40

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