Class: Mindee::Parsing::Common::OCR::OCRLine

Inherits:
Array
  • Object
show all
Defined in:
lib/mindee/parsing/common/ocr/ocr.rb

Overview

A list of words which are on the same line.

Instance Method Summary collapse

Constructor Details

#initialize(prediction = nil, from_array = nil) ⇒ OCRLine

Returns a new instance of OCRLine.

Parameters:

  • prediction (Hash, nil) (defaults to: nil)
  • from_array (Array<OCRWord>, nil) (defaults to: nil)


40
41
42
43
44
45
46
# File 'lib/mindee/parsing/common/ocr/ocr.rb', line 40

def initialize(prediction = nil, from_array = nil)
  if !prediction.nil?
    super(prediction.map { |word_prediction| OCRWord.new(word_prediction) })
  elsif !from_array.nil?
    super(from_array)
  end
end

Instance Method Details

#sort_on_xOCRLine

Sort the words on the line from left to right.

Returns:



50
51
52
53
# File 'lib/mindee/parsing/common/ocr/ocr.rb', line 50

def sort_on_x
  from_array = sort_by { |word| Geometry.get_min_max_x(word.polygon).min }
  OCRLine.new(nil, from_array)
end

#to_sString

Returns:

  • (String)


56
57
58
# File 'lib/mindee/parsing/common/ocr/ocr.rb', line 56

def to_s
  each(&:to_s).join(' ')
end