Class: SPARQL::Algebra::Operator::Concat
- Inherits:
-
SPARQL::Algebra::Operator
- Object
- SPARQL::Algebra::Operator
- SPARQL::Algebra::Operator::Concat
- Includes:
- Evaluatable
- Defined in:
- lib/sparql/algebra/operator/concat.rb
Overview
A SPARQL concat
operator.
The CONCAT function corresponds to the XPath fn:concat function. The function accepts string literals as arguments.
[121] BuiltInCall ::= … ‘CONCAT’ ExpressionList
Constant Summary collapse
- NAME =
:concat
Constants inherited from SPARQL::Algebra::Operator
Constants included from Expression
Instance Attribute Summary
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary collapse
-
#evaluate(bindings, **options) ⇒ RDF::Term
The lexical form of the returned literal is obtained by concatenating the lexical forms of its inputs.
-
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
Methods included from Evaluatable
#apply, #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, #initialize, #inspect, #ndvars, #node?, #operand, #optimize, #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?, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?
Constructor Details
This class inherits a constructor from SPARQL::Algebra::Operator
Instance Method Details
#evaluate(bindings, **options) ⇒ RDF::Term
The lexical form of the returned literal is obtained by concatenating the lexical forms of its inputs. If all input literals are typed literals of type xsd:string, then the returned literal is also of type xsd:string
, if all input literals are plain literals with identical language tag, then the returned literal is a plain literal with the same language tag, in all other cases, the returned literal is a simple literal.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sparql/algebra/operator/concat.rb', line 50 def evaluate(bindings, **) ops = operands.map {|op| op.evaluate(bindings, **.merge(depth: [:depth].to_i + 1))} # rdf:nil is like empty string if ops == [RDF.nil] return RDF::Literal.new("") end raise TypeError, "expected all plain literal operands" unless ops.all? {|op| op.literal? && op.plain?} ops.inject do |memo, op| case when memo.datatype == RDF::XSD.string && op.datatype == RDF::XSD.string RDF::Literal.new("#{memo}#{op}", datatype: RDF::XSD.string) when memo.has_language? && memo.language == op.language RDF::Literal.new("#{memo}#{op}", language: memo.language) else RDF::Literal.new("#{memo}#{op}") end end end |
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
77 78 79 |
# File 'lib/sparql/algebra/operator/concat.rb', line 77 def to_sparql(**) "CONCAT(#{operands.to_sparql(delimiter: ', ', **)})" end |