Class: SPARQL::Algebra::Operator::GroupConcat
- Inherits:
-
SPARQL::Algebra::Operator
- Object
- SPARQL::Algebra::Operator
- SPARQL::Algebra::Operator::GroupConcat
- Includes:
- Aggregate
- Defined in:
- lib/sparql/algebra/operator/group_concat.rb
Overview
The SPARQL groupconcat
set function.
GroupConcat is a set function which performs a string concatenation across the values of an expression with a group. The order of the strings is not specified. The separator character used in the concatenation may be given with the scalar argument SEPARATOR.
[127] Aggregate::= … | ‘GROUP_CONCAT’ ‘(’ ‘DISTINCT’? Expression ( ‘;’ ‘SEPARATOR’ ‘=’ String )? ‘)’
Constant Summary collapse
- NAME =
:group_concat
Constants inherited from SPARQL::Algebra::Operator
Constants included from Expression
Instance Attribute Summary
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary collapse
-
#aggregate(solutions = [], **options) ⇒ RDF::Term
abstract
One, two or three operands, the first may be
distinct
, the last operand, if it exists, is a separator, defaulting to ‘ ’. -
#apply(enum, separator, **options) ⇒ RDF::Term
GroupConcat is a set function which performs a string concatenation across the values of an expression with a group.
-
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
Methods included from Aggregate
#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?, #evaluate, 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
#aggregate(solutions = [], **options) ⇒ RDF::Term
One, two or three operands, the first may be distinct
, the last operand, if it exists, is a separator, defaulting to ‘ ’.
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sparql/algebra/operator/group_concat.rb', line 53 def aggregate(solutions = [], **) operands.shift if distinct = (operands.first == :distinct) sep = operands.length == 2 ? operand(0).last : RDF::Literal(' ') args_enum = solutions.map do |solution| begin operands.last.evaluate(solution, **.merge(depth: [:depth].to_i + 1)) rescue TypeError # Ignore errors nil end end apply(distinct ? args_enum.uniq : args_enum, sep) end |
#apply(enum, separator, **options) ⇒ RDF::Term
GroupConcat is a set function which performs a string concatenation across the values of an expression with a group. The order of the strings is not specified. The separator character used in the concatenation may be given with the scalar argument SEPARATOR.
74 75 76 |
# File 'lib/sparql/algebra/operator/group_concat.rb', line 74 def apply(enum, separator, **) RDF::Literal(enum.flatten.map(&:to_s).join(separator.to_s)) end |
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
83 84 85 86 87 88 89 90 91 |
# File 'lib/sparql/algebra/operator/group_concat.rb', line 83 def to_sparql(**) distinct = operands.first == :distinct args = distinct ? operands[1..-1] : operands separator = args.first.last if args.first.is_a?(Array) && args.first.first == :separator args = args[1..-1] if separator str = "GROUP_CONCAT(#{'DISTINCT ' if distinct}#{args.to_sparql(delimiter: ', ', **)}" str << "; SEPARATOR=#{separator.to_sparql}" if separator str << ")" end |