Class: SPARQL::Algebra::Operator::Sample

Inherits:
Unary show all
Includes:
Aggregate
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-b66c70fb77a0/lib/sparql/algebra/operator/sample.rb

Overview

The SPARQL sample set function.

Examples:

(prefix ((: <http://www.example.org/>))
  (filter (|| (|| (= ?sample 1.0) (= ?sample 2.2)) (= ?sample 3.5))
    (project (?sample)
      (extend ((?sample ?.0))
        (group () ((?.0 (sample ?o)))
          (bgp (triple ?s :dec ?o)))))))

See Also:

Constant Summary collapse

NAME =
:sample

Constants inherited from Unary

Unary::ARITY

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

#aggregate, #replace_aggregate!, #replace_vars!

Methods inherited from Unary

#initialize

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::Unary

Instance Method Details

#apply(enum) ⇒ RDF::Term

Sample is a set function which returns an arbitrary value from the multiset passed to it.

Parameters:

Returns:

Raises:

  • (TypeError)

    If enum is empty



27
28
29
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-b66c70fb77a0/lib/sparql/algebra/operator/sample.rb', line 27

def apply(enum)
  enum.detect(lambda {raise TypeError, "Sampling an empty multiset"}) {|e| e.first}.first
end