Class: 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
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!
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 |