Class: Kreuzberg::Config::Hierarchy

Inherits:
Object
  • Object
show all
Defined in:
lib/kreuzberg/config.rb

Overview

Hierarchy detection configuration

Examples:

hierarchy = Hierarchy.new(enabled: true, k_clusters: 6, include_bbox: true)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enabled: true, k_clusters: 6, include_bbox: true, ocr_coverage_threshold: nil) ⇒ Hierarchy

Returns a new instance of Hierarchy.



351
352
353
354
355
356
357
358
359
360
361
# File 'lib/kreuzberg/config.rb', line 351

def initialize(
  enabled: true,
  k_clusters: 6,
  include_bbox: true,
  ocr_coverage_threshold: nil
)
  @enabled = enabled ? true : false
  @k_clusters = k_clusters&.to_i || 6
  @include_bbox = include_bbox ? true : false
  @ocr_coverage_threshold = ocr_coverage_threshold&.to_f
end

Instance Attribute Details

#enabledObject (readonly)

Returns the value of attribute enabled.



349
350
351
# File 'lib/kreuzberg/config.rb', line 349

def enabled
  @enabled
end

#include_bboxObject (readonly)

Returns the value of attribute include_bbox.



349
350
351
# File 'lib/kreuzberg/config.rb', line 349

def include_bbox
  @include_bbox
end

#k_clustersObject (readonly)

Returns the value of attribute k_clusters.



349
350
351
# File 'lib/kreuzberg/config.rb', line 349

def k_clusters
  @k_clusters
end

#ocr_coverage_thresholdObject (readonly)

Returns the value of attribute ocr_coverage_threshold.



349
350
351
# File 'lib/kreuzberg/config.rb', line 349

def ocr_coverage_threshold
  @ocr_coverage_threshold
end

Class Method Details

.from_h(hash) ⇒ Object



372
373
374
375
376
377
# File 'lib/kreuzberg/config.rb', line 372

def self.from_h(hash)
  return nil if hash.nil?
  return hash if hash.is_a?(self)

  new(**hash.transform_keys(&:to_sym)) if hash.is_a?(Hash)
end

Instance Method Details

#to_hObject



363
364
365
366
367
368
369
370
# File 'lib/kreuzberg/config.rb', line 363

def to_h
  {
    enabled: @enabled,
    k_clusters: @k_clusters,
    include_bbox: @include_bbox,
    ocr_coverage_threshold: @ocr_coverage_threshold
  }.compact
end