Class: Clusta::Transforms::NeighborhoodsToDegreePairs::Reducer

Inherits:
Wukong::Streamer::AccumulatingReducer
  • Object
show all
Includes:
Wukong::Streamer::StructRecordizer
Defined in:
lib/clusta/transforms/neighborhoods_to_degree_pairs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#degree_pairsObject

Returns the value of attribute degree_pairs.



24
25
26
# File 'lib/clusta/transforms/neighborhoods_to_degree_pairs.rb', line 24

def degree_pairs
  @degree_pairs
end

#source_degreeObject

Returns the value of attribute source_degree.



24
25
26
# File 'lib/clusta/transforms/neighborhoods_to_degree_pairs.rb', line 24

def source_degree
  @source_degree
end

#source_in_degreeObject

Returns the value of attribute source_in_degree.



24
25
26
# File 'lib/clusta/transforms/neighborhoods_to_degree_pairs.rb', line 24

def source_in_degree
  @source_in_degree
end

#source_out_degreeObject

Returns the value of attribute source_out_degree.



24
25
26
# File 'lib/clusta/transforms/neighborhoods_to_degree_pairs.rb', line 24

def source_out_degree
  @source_out_degree
end

Instance Method Details

#accumulate(new_degree_pair, *record) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/clusta/transforms/neighborhoods_to_degree_pairs.rb', line 42

def accumulate new_degree_pair, *record
  self.degree_pairs      << new_degree_pair
  if new_degree_pair.directed?
    self.source_in_degree  += new_degree_pair.source_in_degree_value
    self.source_out_degree += new_degree_pair.source_out_degree_value
  else
    self.source_degree += new_degree_pair.source_degree_value
  end
end

#finalize(&block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/clusta/transforms/neighborhoods_to_degree_pairs.rb', line 52

def finalize &block
  degree_pairs.each do |degree_pair|
    if degree_pair.directed?
      degree_pair.source_in_degree_value  = source_in_degree
      degree_pair.source_out_degree_value = source_out_degree
    else
      degree_pair.source_degree_value = source_degree
    end
    emit degree_pair
  end
end

#get_key(new_degree_pair, *record) ⇒ Object



28
29
30
# File 'lib/clusta/transforms/neighborhoods_to_degree_pairs.rb', line 28

def get_key new_degree_pair, *record
  new_degree_pair.source_label
end

#start!(new_degree_pair, *record) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/clusta/transforms/neighborhoods_to_degree_pairs.rb', line 32

def start! new_degree_pair, *record
  self.degree_pairs = []
  if new_degree_pair.directed?
    self.source_in_degree  = 0
    self.source_out_degree = 0
  else
    self.source_degree = 0
  end
end