Class: SPARQL::Algebra::Operator::GroupConcat
- Inherits:
-
SPARQL::Algebra::Operator
- Object
- SPARQL::Algebra::Operator
- SPARQL::Algebra::Operator::GroupConcat
- Includes:
- Aggregate
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/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.
If all operands are language-tagged strings with the same language (and direction), the result shares the language (and direction).
[127] Aggregate::= ... | 'GROUP_CONCAT' '(' 'DISTINCT'? Expression ( ';' 'SEPARATOR' '=' String )? ')'
Constant Summary collapse
- NAME =
:group_concat
Constants inherited from SPARQL::Algebra::Operator
Constants included from Expression
Constants included from RDF::Util::Logger
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, #formulae, #initialize, #inspect, #mergable?, #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?
Methods included from RDF::Util::Logger
#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger
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 ' '.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/group_concat.rb', line 55 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.
76 77 78 79 80 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/group_concat.rb', line 76 def apply(enum, separator, **) op1_lang = enum.first.language lang = op1_lang if op1_lang && enum.all? {|v| v.language == op1_lang} RDF::Literal(enum.flatten.map(&:to_s).join(separator.to_s), language: lang) end |
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
87 88 89 90 91 92 93 94 95 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/group_concat.rb', line 87 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 |