Class: SPARQL::Algebra::Operator::SubStr
- Inherits:
-
Ternary
- Object
- SPARQL::Algebra::Operator
- Ternary
- SPARQL::Algebra::Operator::SubStr
- Includes:
- Evaluatable
- Defined in:
- lib/sparql/algebra/operator/substr.rb
Overview
A SPARQL substr
operator.
[123] SubstringExpression ::= ‘SUBSTR’ ‘(’ Expression ‘,’ Expression ( ‘,’ Expression )? ‘)’
Constant Summary collapse
- NAME =
:substr
Constants inherited from Ternary
Constants inherited from SPARQL::Algebra::Operator
Constants included from Expression
Instance Attribute Summary
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary collapse
-
#apply(source, startingLoc, length, **options) ⇒ RDF::Literal
The substr function corresponds to the XPath fn:substring function and returns a literal of the same kind (simple literal, literal with language tag, xsd:string typed literal) as the source input parameter but with a lexical form formed from the substring of the lexcial form of the source.
-
#initialize(source, startingLoc, length = RDF::Literal(""), **options) ⇒ SubStr
constructor
Initializes a new operator instance.
-
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
-
#to_sxp_bin ⇒ Array
Returns the SPARQL S-Expression (SSE) representation of this expression.
Methods included from Evaluatable
#evaluate, #memoize, #replace_aggregate!, #replace_vars!
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, #inspect, #ndvars, #node?, #operand, #optimize, #optimize!, #parent, #parent=, #prefixes, prefixes, prefixes=, #rewrite, #to_binary, to_sparql, #to_sxp, #validate!, #variable?, #variables, #vars
Methods included from Expression
cast, #constant?, #evaluate, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, parse, register_extension, #valid?, #validate!, #variable?
Constructor Details
#initialize(source, startingLoc, length = RDF::Literal(""), **options) ⇒ SubStr
Initializes a new operator instance.
37 38 39 |
# File 'lib/sparql/algebra/operator/substr.rb', line 37 def initialize(source, startingLoc, length = RDF::Literal(""), **) super end |
Instance Method Details
#apply(source, startingLoc, length, **options) ⇒ RDF::Literal
The substr function corresponds to the XPath fn:substring function and returns a literal of the same kind (simple literal, literal with language tag, xsd:string typed literal) as the source input parameter but with a lexical form formed from the substring of the lexcial form of the source.
The arguments startingLoc and length may be derived types of xsd:integer.
The index of the first character in a strings is 1.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/sparql/algebra/operator/substr.rb', line 64 def apply(source, startingLoc, length, **) raise TypeError, "expected a plain RDF::Literal, but got #{source.inspect}" unless source.literal? && source.plain? text = text.to_s raise TypeError, "expected an integer, but got #{startingLoc.inspect}" unless startingLoc.is_a?(RDF::Literal::Integer) startingLoc = startingLoc.to_i if length == RDF::Literal("") RDF::Literal(source.to_s[(startingLoc-1)..-1], datatype: source.datatype, language: source.language) else raise TypeError, "expected an integer, but got #{length.inspect}" unless length.is_a?(RDF::Literal::Integer) length = length.to_i RDF::Literal(source.to_s[(startingLoc-1), length], datatype: source.datatype, language: source.language) end end |
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
96 97 98 |
# File 'lib/sparql/algebra/operator/substr.rb', line 96 def to_sparql(**) "SUBSTR(" + operands.to_sparql(delimiter: ', ', **) + ")" end |