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

Inherits:
Binary show all
Includes:
Evaluatable
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/operator/same_term.rb

Overview

The SPARQL sameTerm operator.

[121] BuiltInCall ::= ... | 'sameTerm' '(' Expression ',' Expression ')'

Examples:

SPARQL Grammar

PREFIX     :    <http://example.org/things#>
SELECT * {
  ?x1 :p ?v1 .
  ?x2 :p ?v2 .
  FILTER sameTerm(?v1, ?v2)
}

SSE

(prefix
 ((: <http://example.org/things#>))
 (filter (sameTerm ?v1 ?v2)
  (bgp (triple ?x1 :p ?v1) (triple ?x2 :p ?v2))))

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

Constants included from Expression

Expression::PATTERN_PARENTS

Constants included from RDF::Util::Logger

RDF::Util::Logger::IOWrapper

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_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!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

Methods included from RDF::Util::Logger

#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger

Constructor Details

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

Instance Method Details

#apply(term1, term2, **options) ⇒ 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



38
39
40
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/operator/same_term.rb', line 38

def apply(term1, term2, **options)
  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:



49
50
51
52
53
54
55
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/operator/same_term.rb', line 49

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

#to_sparql(**options) ⇒ String

Returns a partial SPARQL grammar for this operator.

Returns:



62
63
64
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/operator/same_term.rb', line 62

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