Class: Mindee::Parsing::Common::Inference

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

Overview

Abstract class for prediction Inferences Holds prediction for a page or entire document.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_prediction) ⇒ Inference

Returns a new instance of Inference.

Parameters:

  • raw_prediction (Hash)


39
40
41
42
43
# File 'lib/mindee/parsing/common/inference.rb', line 39

def initialize(raw_prediction)
  @is_rotation_applied = raw_prediction['is_rotation_applied']
  @product = Product.new(raw_prediction['product'])
  @pages = [] # : Array[Page]
end

Instance Attribute Details

#endpoint_nameString (readonly)

Name of the endpoint for this product.

Returns:

  • (String)


22
23
24
# File 'lib/mindee/parsing/common/inference.rb', line 22

def endpoint_name
  @endpoint_name
end

#endpoint_versionString (readonly)

Version for this product.

Returns:

  • (String)


25
26
27
# File 'lib/mindee/parsing/common/inference.rb', line 25

def endpoint_version
  @endpoint_version
end

#has_asyncbool (readonly)

Whether this product has access to an asynchronous endpoint.

Returns:

  • (bool)


28
29
30
# File 'lib/mindee/parsing/common/inference.rb', line 28

def has_async
  @has_async
end

#has_syncbool (readonly)

Whether this product has access to synchronous endpoint.

Returns:

  • (bool)


31
32
33
# File 'lib/mindee/parsing/common/inference.rb', line 31

def has_sync
  @has_sync
end

#is_rotation_appliedbool (readonly)

Returns:

  • (bool)


13
14
15
# File 'lib/mindee/parsing/common/inference.rb', line 13

def is_rotation_applied
  @is_rotation_applied
end

#pagesArray<Mindee::Parsing::Common::Page> (readonly)

Returns:



15
16
17
# File 'lib/mindee/parsing/common/inference.rb', line 15

def pages
  @pages
end

#predictionMindee::Parsing::Common::Prediction (readonly)



17
18
19
# File 'lib/mindee/parsing/common/inference.rb', line 17

def prediction
  @prediction
end

#productMindee::Parsing::Common::Product (readonly)



19
20
21
# File 'lib/mindee/parsing/common/inference.rb', line 19

def product
  @product
end

Instance Method Details

#to_sString

Returns:

  • (String)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mindee/parsing/common/inference.rb', line 46

def to_s
  is_rotation_applied = @is_rotation_applied ? 'Yes' : 'No'
  out_str = String.new
  out_str << "Inference\n#########"
  out_str << "\n:Product: #{@product.name} v#{@product.version}"
  out_str << "\n:Rotation applied: #{is_rotation_applied}"
  out_str << "\n\nPrediction\n=========="
  out_str << "\n#{@prediction.to_s.size.positive? ? "#{@prediction}\n" : ''}"
  if @pages.any? { |page| !page.prediction.nil? }
    out_str << "\nPage Predictions\n================\n\n"
    out_str << @pages.map(&:to_s).join("\n\n")
  end
  out_str.rstrip!
  out_str
end