Class: Broadlistening::Context
- Inherits:
-
Object
- Object
- Broadlistening::Context
- Defined in:
- lib/broadlistening/context.rb
Overview
Manages pipeline execution context - all data flowing through the pipeline.
The Context holds all intermediate results and provides methods for loading from / saving to disk for incremental execution support.
Constant Summary collapse
- OUTPUT_FILES =
Output file mapping for each step
{ extraction: "extraction.json", embedding: "embeddings.json", clustering: "clustering.json", initial_labelling: "initial_labels.json", merge_labelling: "merge_labels.json", overview: "overview.json", aggregation: "result.json" }.freeze
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#cluster_results ⇒ Object
Returns the value of attribute cluster_results.
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#initial_labels ⇒ Object
Returns the value of attribute initial_labels.
-
#labels ⇒ Object
Returns the value of attribute labels.
-
#output_dir ⇒ Object
Returns the value of attribute output_dir.
-
#overview ⇒ Object
Returns the value of attribute overview.
-
#relations ⇒ Object
Returns the value of attribute relations.
-
#result ⇒ Object
Returns the value of attribute result.
-
#umap_coords ⇒ Object
Returns the value of attribute umap_coords.
Class Method Summary collapse
-
.load_from_dir(output_dir) ⇒ Context
Load existing context from output directory.
Instance Method Summary collapse
-
#initialize ⇒ Context
constructor
A new instance of Context.
-
#save_step(step_name, output_dir) ⇒ Object
Save a step's output to file.
-
#to_h ⇒ Hash
Convert to hash for serialization.
Constructor Details
#initialize ⇒ Context
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/broadlistening/context.rb', line 56 def initialize @comments = [] @arguments = [] @relations = [] @cluster_results = {} @umap_coords = nil @initial_labels = {} @labels = {} @overview = nil @result = nil @output_dir = nil end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
21 22 23 |
# File 'lib/broadlistening/context.rb', line 21 def arguments @arguments end |
#cluster_results ⇒ Object
Returns the value of attribute cluster_results.
21 22 23 |
# File 'lib/broadlistening/context.rb', line 21 def cluster_results @cluster_results end |
#comments ⇒ Object
Returns the value of attribute comments.
21 22 23 |
# File 'lib/broadlistening/context.rb', line 21 def comments @comments end |
#initial_labels ⇒ Object
Returns the value of attribute initial_labels.
21 22 23 |
# File 'lib/broadlistening/context.rb', line 21 def initial_labels @initial_labels end |
#labels ⇒ Object
Returns the value of attribute labels.
21 22 23 |
# File 'lib/broadlistening/context.rb', line 21 def labels @labels end |
#output_dir ⇒ Object
Returns the value of attribute output_dir.
21 22 23 |
# File 'lib/broadlistening/context.rb', line 21 def output_dir @output_dir end |
#overview ⇒ Object
Returns the value of attribute overview.
21 22 23 |
# File 'lib/broadlistening/context.rb', line 21 def overview @overview end |
#relations ⇒ Object
Returns the value of attribute relations.
21 22 23 |
# File 'lib/broadlistening/context.rb', line 21 def relations @relations end |
#result ⇒ Object
Returns the value of attribute result.
21 22 23 |
# File 'lib/broadlistening/context.rb', line 21 def result @result end |
#umap_coords ⇒ Object
Returns the value of attribute umap_coords.
21 22 23 |
# File 'lib/broadlistening/context.rb', line 21 def umap_coords @umap_coords end |
Class Method Details
.load_from_dir(output_dir) ⇒ Context
Load existing context from output directory
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/broadlistening/context.rb', line 41 def self.load_from_dir(output_dir) context = new dir = Pathname.new(output_dir) OUTPUT_FILES.each do |step, filename| file = dir / filename next unless file.exist? data = JSON.parse(file.read, symbolize_names: true) context.send(:merge_step_data, step, data) end context end |
Instance Method Details
#save_step(step_name, output_dir) ⇒ Object
Save a step's output to file
73 74 75 76 77 78 79 80 81 |
# File 'lib/broadlistening/context.rb', line 73 def save_step(step_name, output_dir) dir = Pathname.new(output_dir) filename = OUTPUT_FILES[step_name] return unless filename FileUtils.mkdir_p(dir) data = extract_step_output(step_name) File.write(dir / filename, JSON.pretty_generate(data)) end |
#to_h ⇒ Hash
Convert to hash for serialization
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/broadlistening/context.rb', line 86 def to_h { comments: @comments.map(&:to_h), arguments: @arguments.map(&:to_h), relations: @relations, cluster_results: @cluster_results, umap_coords: @umap_coords, initial_labels: @initial_labels, labels: @labels, overview: @overview, result: @result } end |