Class: Alf::Types::Summarization

Inherits:
Object
  • Object
show all
Defined in:
lib/alf/types/summarization.rb

Overview

Encapsulates a Summarization information.

Instance Method Summary collapse

Instance Method Details

#finalize(aggs) ⇒ Tuple

Finalizes the summarization

Returns:

  • (Tuple)

    the finalized aggregated tuple


39
40
41
# File 'lib/alf/types/summarization.rb', line 39

def finalize(aggs)
  hmap{|k,v| v.finalize(aggs[k]) }
end

#happens(aggs, scope) ⇒ Support::TupleScope

Computes the resulting aggregation from aggs if tuple happens.

Returns:


32
33
34
# File 'lib/alf/types/summarization.rb', line 32

def happens(aggs, scope)
  hmap{|k,v| v.happens(aggs[k], scope) }
end

#inspectObject

Returns a string representation of this expression


87
88
89
90
91
# File 'lib/alf/types/summarization.rb', line 87

def inspect
  to_ruby_literal
rescue NotImplementedError
  super
end

#leastTuple

Computes the least tuple.

Returns:

  • (Tuple)

    a tuple with least values for each attribute


25
26
27
# File 'lib/alf/types/summarization.rb', line 25

def least
  hmap{|k,v| v.least }
end

#summarize(enum) ⇒ Object

Summarizes an enumeration of tuples.

Parameters:

  • enum (Enumerable)

    an enumeration of tuples


47
48
49
50
# File 'lib/alf/types/summarization.rb', line 47

def summarize(enum)
  scope = Support::TupleScope.new
  finalize(enum.inject(least){|m,t| happens(m, scope.__set_tuple(t))})
end

#to_attr_listAttrList

Converts to an attribute list.

Returns:

  • (AttrList)

    a list of computed attribute names


67
68
69
# File 'lib/alf/types/summarization.rb', line 67

def to_attr_list
  AttrList.new(keys)
end

#to_headingHeading

Converts to an Heading.

Returns:


60
61
62
# File 'lib/alf/types/summarization.rb', line 60

def to_heading
  Heading.new hmap{|name,agg| agg.infer_type}
end

#to_lispyString

Returns a lispy expression.

Returns:

  • (String)

    a lispy expression for this summarization


74
75
76
# File 'lib/alf/types/summarization.rb', line 74

def to_lispy
  "{" << map{|k,v| "#{k}: #{Support.to_lispy(v)}" }.join(', ') << "}"
end

#to_ruby_literalString

Returns a ruby literal for this expression.

Returns:

  • (String)

    a literal s.t. `eval(self.to_ruby_literal) == self`


81
82
83
84
# File 'lib/alf/types/summarization.rb', line 81

def to_ruby_literal
  map = hmap{|k,v| "#{v.has_source_code!}" }
  "Alf::Summarization[#{Support.to_ruby_literal(map)}]"
end

#to_summarizationObject

Returns self


53
54
55
# File 'lib/alf/types/summarization.rb', line 53

def to_summarization
  self
end