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

Inherits:
Object
  • Object
show all
Defined in:
lib/mindee/v1/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)


42
43
44
45
46
47
# File 'lib/mindee/v1/parsing/common/inference.rb', line 42

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

Instance Attribute Details

#endpoint_nameString (readonly)

Name of the endpoint for this product.

Returns:

  • (String)


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

def endpoint_name
  @endpoint_name
end

#endpoint_versionString (readonly)

Version for this product.

Returns:

  • (String)


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

def endpoint_version
  @endpoint_version
end

#extrasMindee::V1::Parsing::Common::Extras::Extras (readonly)

Returns Potential Extras fields sent back along the prediction.

Returns:



34
35
36
# File 'lib/mindee/v1/parsing/common/inference.rb', line 34

def extras
  @extras
end

#has_asyncbool (readonly)

Whether this product has access to an asynchronous endpoint.

Returns:

  • (bool)


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

def has_async
  @has_async
end

#has_syncbool (readonly)

Whether this product has access to synchronous endpoint.

Returns:

  • (bool)


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

def has_sync
  @has_sync
end

#is_rotation_appliedbool (readonly)

Returns:

  • (bool)


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

def is_rotation_applied
  @is_rotation_applied
end

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



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

def pages
  @pages
end

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



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

def prediction
  @prediction
end

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



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

def product
  @product
end

Instance Method Details

#to_sString

Returns:

  • (String)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/mindee/v1/parsing/common/inference.rb', line 50

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}\n" if @prediction.to_s.size.positive?}"
  if @pages.any? { |page| !page.prediction.nil? }
    out_str << "\nPage Predictions\n================\n\n"
    out_str << @pages.join("\n\n")
  end
  out_str.rstrip!
  out_str
end