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, 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
54
55
# File 'lib/mindee/parsing/common/ocr/ocr.rb', line 50

def sort_on_x
  from_array = sort do |word1, word2|
    Geometry.get_min_max_x(word1.polygon).min <=> Geometry.get_min_max_x(word2.polygon).min
  end
  OcrLine.new(nil, from_array)
end

#to_sString

Returns:

  • (String)


58
59
60
# File 'lib/mindee/parsing/common/ocr/ocr.rb', line 58

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