Class: Broadlistening::Steps::MergeLabelling

Inherits:
BaseStep
  • Object
show all
Defined in:
lib/broadlistening/steps/merge_labelling.rb

Instance Attribute Summary

Attributes inherited from BaseStep

#config, #context

Instance Method Summary collapse

Methods inherited from BaseStep

#initialize

Constructor Details

This class inherits a constructor from Broadlistening::Steps::BaseStep

Instance Method Details

#executeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/broadlistening/steps/merge_labelling.rb', line 6

def execute
  return context if context.initial_labels.empty?

  all_labels = context.initial_labels.dup

  # Build parent-child relationships and merge from bottom to top
  levels = context.cluster_results.keys.sort.reverse
  levels[1..].each do |level|
    parent_labels = merge_labels_for_level(context.arguments, all_labels, context.cluster_results, level)
    parent_labels.each { |l| all_labels[l[:cluster_id]] = l }
  end

  context.labels = all_labels
  context
end