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

Inherits:
Operator::Unary
  • Object
show all
Includes:
Evaluatable
Defined in:
lib/sparql/algebra/operator/encode_for_uri.rb

Overview

The SPARQL logical abs operator.

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

Examples:

SPARQL Grammar

PREFIX : <http://example.org/>
SELECT ?s ?str (ENCODE_FOR_URI(?str) AS ?encoded) WHERE {
  ?s :str ?str
}

SSE

(prefix ((: <http://example.org/>))
 (project (?s ?str ?encoded)
  (extend ((?encoded (encode_for_uri ?str)))
   (bgp (triple ?s :str ?str)))))

See Also:

Constant Summary collapse

NAME =
:encode_for_uri

Instance Method Summary collapse

Methods included from Evaluatable

#evaluate, #memoize, #replace_aggregate!, #replace_vars!

Instance Method Details

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

  • operand (RDF::Literal)

    the operand

Returns:

  • (RDF::Literal)

    literal of same type

Raises:

  • (TypeError)

    if the operand is not a literal value



41
42
43
44
45
46
# File 'lib/sparql/algebra/operator/encode_for_uri.rb', line 41

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

#to_sparql(**options) ⇒ String

Returns a partial SPARQL grammar for this operator.

Returns:

  • (String)


53
54
55
# File 'lib/sparql/algebra/operator/encode_for_uri.rb', line 53

def to_sparql(**options)
  "ENCODE_FOR_URI(#{operands.last.to_sparql(**options)})"
end