class SPARQL::Algebra::Operator::GroupConcat

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.

@example

(prefix ((: <http://www.example.org/>))
  (filter (|| (= ?g "1 22") (= ?g "22 1"))
    (project (?g)
      (extend ((?g ??.0))
        (group () ((??.0 (group_concat ?o)))
          (bgp (triple ??.0 :p1 ?o)))))))

@see www.w3.org/TR/sparql11-query/#defn_aggGroupConcat

Constants

NAME

Public Instance Methods

aggregate(solutions = [], **options) click to toggle source

One, two or three operands, the first may be `distinct`, the last operand, if it exists, is a separator, defaulting to ' '.

@param [Enumerable<RDF::Query::Solution>] solutions ([])

an enumerable set of query solutions

@param [Hash{Symbol => Object}] options ({})

options passed from query

@return [RDF::Term] @raise [TypeError] @abstract

# File lib/sparql/algebra/operator/group_concat.rb, line 32
def aggregate(solutions = [], **options)
  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, depth: options[:depth].to_i + 1, **options)
    rescue TypeError
      # Ignore errors
      nil
    end
  end
  apply(distinct ? args_enum.uniq : args_enum, sep)
end
apply(enum, separator, **options) click to toggle source

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.

@param [Enumerable<Array<RDF::Term>>] enum

enum of evaluated operand

@return [RDF::Term] An arbitrary term @raise [TypeError] If enum is empty

# File lib/sparql/algebra/operator/group_concat.rb, line 53
def apply(enum, separator, **options)
  RDF::Literal(enum.flatten.map(&:to_s).join(separator.to_s))
end