Class: SPARQL::Algebra::Operator::GroupConcat

Inherits:
SPARQL::Algebra::Operator show all
Includes:
Aggregate
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/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.

Examples:

(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 Also:

Constant Summary collapse

NAME =
:group_concat

Constants inherited from SPARQL::Algebra::Operator

ARITY, IsURI, URI

Instance Attribute Summary

Attributes inherited from SPARQL::Algebra::Operator

#operands

Instance Method Summary collapse

Methods included from Aggregate

#replace_aggregate!, #replace_vars!

Methods inherited from SPARQL::Algebra::Operator

#aggregate?, arity, #base_uri, base_uri, base_uri=, #boolean, #constant?, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #initialize, #inspect, #ndvars, #node?, #operand, #optimize, #parent, #parent=, prefixes, #prefixes, prefixes=, #rewrite, #to_binary, #to_sxp, #to_sxp_bin, #validate!, #variable?, #vars

Methods included from Expression

cast, #constant?, #evaluate, extension, extensions, for, #invalid?, new, #node?, open, #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

This method is abstract.

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

Parameters:

Returns:

Raises:

  • (TypeError)


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/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, options.merge(depth: options[:depth].to_i + 1))
    rescue TypeError
      # Ignore errors
      nil
    end
  end
  apply(distinct ? args_enum.uniq : args_enum, sep)
end

#apply(enum, separator) ⇒ 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.

Parameters:

Returns:

Raises:

  • (TypeError)

    If enum is empty



53
54
55
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/group_concat.rb', line 53

def apply(enum, separator)
  RDF::Literal(enum.flatten.map(&:to_s).join(separator.to_s))
end