Class: SPARQL::Algebra::Operator::Sample
- Inherits:
-
SPARQL::Algebra::Operator
- Object
- SPARQL::Algebra::Operator
- SPARQL::Algebra::Operator::Sample
- Includes:
- Aggregate
- Defined in:
- vendor/bundler/ruby/3.0.0/bundler/gems/sparql-ffa592c8f275/lib/sparql/algebra/operator/sample.rb
Overview
The SPARQL sample
set function.
Constant Summary collapse
- NAME =
:sample
Constants inherited from SPARQL::Algebra::Operator
Instance Attribute Summary
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary collapse
-
#apply(enum) ⇒ RDF::Term
Sample is a set function which returns an arbitrary value from the multiset passed to it.
-
#initialize(*operands, **options) ⇒ Sample
constructor
A new instance of Sample.
Methods included from Aggregate
#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, #inspect, #ndvars, #node?, #operand, #optimize, #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, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?
Constructor Details
#initialize(*operands, **options) ⇒ Sample
Returns a new instance of Sample.
20 21 22 23 24 25 |
# File 'vendor/bundler/ruby/3.0.0/bundler/gems/sparql-ffa592c8f275/lib/sparql/algebra/operator/sample.rb', line 20 def initialize(*operands, **) raise ArgumentError, "sample operator accepts at most one argument with an optional :distinct" if (operands - %i{distinct}).length != 1 super end |
Instance Method Details
#apply(enum) ⇒ RDF::Term
Sample is a set function which returns an arbitrary value from the multiset passed to it.
34 35 36 |
# File 'vendor/bundler/ruby/3.0.0/bundler/gems/sparql-ffa592c8f275/lib/sparql/algebra/operator/sample.rb', line 34 def apply(enum) enum.detect(lambda {raise TypeError, "Sampling an empty multiset"}) {|e| e.first}.first end |