Class: SPARQL::Algebra::Operator::EncodeForURI

Inherits:
Unary show all
Includes:
Evaluatable
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/operator/encode_for_uri.rb

Overview

The SPARQL logical abs operator.

Constant Summary

NAME =
:encode_for_uri

Constants inherited from Unary

Unary::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 Unary

#initialize

Methods inherited from SPARQL::Algebra::Operator

#aggregate?, arity, #base_uri, base_uri, base_uri=, #boolean, #constant?, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #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::Unary

Instance Method Details

#apply(operand) ⇒ RDF::Literal

The ENCODE_FOR_URI function corresponds to the XPath fn:encode-for-uri function. It returns a simple literal with the lexical form obtained from the lexical form of its input after translating reserved characters according to the fn:encode-for-uri function.

Examples:

encode_for_uri("Los Angeles")	"Los%20Angeles"
encode_for_uri("Los Angeles"@en)	"Los%20Angeles"
encode_for_uri("Los Angeles"^^xsd:string)	"Los%20Angeles"

Parameters:

Returns:

Raises:

  • (TypeError)

    if the operand is not a literal value



30
31
32
33
34
35
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/operator/encode_for_uri.rb', line 30

def apply(operand)
  case operand
    when RDF::Literal then RDF::Literal(::URI.encode(operand.to_s))
    else raise TypeError, "expected an RDF::Literal, but got #{operand.inspect}"
  end
end