mindee 4.11.0 → 4.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +20 -0
- data/docs/code_samples/v2_classification.txt +30 -0
- data/docs/code_samples/v2_crop.txt +30 -0
- data/docs/code_samples/{default_v2.txt → v2_extraction.txt} +7 -5
- data/docs/code_samples/v2_extraction_webhook.txt +45 -0
- data/docs/code_samples/v2_ocr.txt +30 -0
- data/docs/code_samples/v2_split.txt +30 -0
- data/lib/mindee/client_v2.rb +69 -17
- data/lib/mindee/errors/mindee_http_error_v2.rb +2 -2
- data/lib/mindee/geometry/point.rb +5 -0
- data/lib/mindee/geometry/polygon.rb +5 -0
- data/lib/mindee/http/mindee_api_v2.rb +62 -12
- data/lib/mindee/input/base_parameters.rb +146 -0
- data/lib/mindee/input/inference_parameters.rb +48 -91
- data/lib/mindee/input/local_response.rb +5 -4
- data/lib/mindee/parsing/v2/field/field_location.rb +1 -1
- data/lib/mindee/parsing/v2/inference.rb +9 -17
- data/lib/mindee/parsing/v2/inference_job.rb +25 -0
- data/lib/mindee/parsing/v2/inference_response.rb +5 -2
- data/lib/mindee/parsing/v2/job.rb +9 -2
- data/lib/mindee/v2/parsing/base_inference.rb +44 -0
- data/lib/mindee/v2/parsing/base_response.rb +13 -0
- data/lib/mindee/v2/product/base_product.rb +27 -0
- data/lib/mindee/v2/product/classification/classification.rb +19 -0
- data/lib/mindee/v2/product/classification/classification_classifier.rb +25 -0
- data/lib/mindee/v2/product/classification/classification_inference.rb +34 -0
- data/lib/mindee/v2/product/classification/classification_response.rb +32 -0
- data/lib/mindee/v2/product/classification/classification_result.rb +27 -0
- data/lib/mindee/v2/product/classification/params/classification_parameters.rb +46 -0
- data/lib/mindee/v2/product/crop/crop.rb +19 -0
- data/lib/mindee/v2/product/crop/crop_inference.rb +34 -0
- data/lib/mindee/v2/product/crop/crop_item.rb +29 -0
- data/lib/mindee/v2/product/crop/crop_response.rb +32 -0
- data/lib/mindee/v2/product/crop/crop_result.rb +34 -0
- data/lib/mindee/v2/product/crop/params/crop_parameters.rb +46 -0
- data/lib/mindee/v2/product/extraction/extraction.rb +19 -0
- data/lib/mindee/v2/product/extraction/extraction_inference.rb +25 -0
- data/lib/mindee/v2/product/extraction/extraction_response.rb +23 -0
- data/lib/mindee/v2/product/extraction/extraction_result.rb +15 -0
- data/lib/mindee/v2/product/extraction/params/extraction_parameters.rb +18 -0
- data/lib/mindee/v2/product/ocr/ocr.rb +19 -0
- data/lib/mindee/v2/product/ocr/ocr_inference.rb +34 -0
- data/lib/mindee/v2/product/ocr/ocr_page.rb +33 -0
- data/lib/mindee/v2/product/ocr/ocr_response.rb +32 -0
- data/lib/mindee/v2/product/ocr/ocr_result.rb +34 -0
- data/lib/mindee/v2/product/ocr/ocr_word.rb +29 -0
- data/lib/mindee/v2/product/ocr/params/ocr_parameters.rb +46 -0
- data/lib/mindee/v2/product/split/params/split_parameters.rb +46 -0
- data/lib/mindee/v2/product/split/split.rb +19 -0
- data/lib/mindee/v2/product/split/split_inference.rb +34 -0
- data/lib/mindee/v2/product/split/split_range.rb +30 -0
- data/lib/mindee/v2/product/split/split_response.rb +32 -0
- data/lib/mindee/v2/product/split/split_result.rb +34 -0
- data/lib/mindee/v2/product.rb +7 -0
- data/lib/mindee/v2.rb +4 -0
- data/lib/mindee/version.rb +1 -1
- data/lib/mindee.rb +7 -0
- data/sig/mindee/client_v2.rbs +11 -7
- data/sig/mindee/errors/mindee_http_error_v2.rbs +1 -1
- data/sig/mindee/geometry/point.rbs +2 -0
- data/sig/mindee/geometry/polygon.rbs +2 -0
- data/sig/mindee/http/mindee_api_v2.rbs +20 -4
- data/sig/mindee/input/base_parameters.rbs +35 -0
- data/sig/mindee/input/inference_parameters.rbs +4 -12
- data/sig/mindee/input/local_response.rbs +2 -2
- data/sig/mindee/parsing/v2/inference.rbs +5 -4
- data/sig/mindee/parsing/v2/inference_job.rbs +12 -0
- data/sig/mindee/parsing/v2/inference_response.rbs +11 -2
- data/sig/mindee/parsing/v2/job.rbs +2 -1
- data/sig/mindee/v2/parsing/base_inference.rbs +18 -0
- data/sig/mindee/v2/parsing/base_response.rbs +11 -0
- data/sig/mindee/v2/product/base_product.rbs +19 -0
- data/sig/mindee/v2/product/classification/classification.rbs +10 -0
- data/sig/mindee/v2/product/classification/classification_classifier.rbs +15 -0
- data/sig/mindee/v2/product/classification/classification_inference.rbs +15 -0
- data/sig/mindee/v2/product/classification/classification_response.rbs +23 -0
- data/sig/mindee/v2/product/classification/classification_result.rbs +15 -0
- data/sig/mindee/v2/product/classification/params/classification_parameters/classification_parameters.rbs +23 -0
- data/sig/mindee/v2/product/crop/crop.rbs +10 -0
- data/sig/mindee/v2/product/crop/crop_inference.rbs +14 -0
- data/sig/mindee/v2/product/crop/crop_item.rbs +15 -0
- data/sig/mindee/v2/product/crop/crop_response.rbs +23 -0
- data/sig/mindee/v2/product/crop/crop_result.rbs +14 -0
- data/sig/mindee/v2/product/crop/params/crop_parameters/crop_parameters.rbs +23 -0
- data/sig/mindee/v2/product/extraction/extraction.rbs +12 -0
- data/sig/mindee/v2/product/extraction/extraction_inference.rbs +14 -0
- data/sig/mindee/v2/product/extraction/extraction_response.rbs +18 -0
- data/sig/mindee/v2/product/extraction/extraction_result.rbs +10 -0
- data/sig/mindee/v2/product/extraction/params/extraction_parameters.rbs +12 -0
- data/sig/mindee/v2/product/ocr/ocr.rbs +10 -0
- data/sig/mindee/v2/product/ocr/ocr_inference.rbs +14 -0
- data/sig/mindee/v2/product/ocr/ocr_page.rbs +15 -0
- data/sig/mindee/v2/product/ocr/ocr_response.rbs +23 -0
- data/sig/mindee/v2/product/ocr/ocr_result.rbs +14 -0
- data/sig/mindee/v2/product/ocr/ocr_word.rbs +15 -0
- data/sig/mindee/v2/product/ocr/params/ocr_parameters/ocr_parameters.rbs +24 -0
- data/sig/mindee/v2/product/split/params/split_parameters/split_parameters.rbs +23 -0
- data/sig/mindee/v2/product/split/split.rbs +10 -0
- data/sig/mindee/v2/product/split/split_inference.rbs +14 -0
- data/sig/mindee/v2/product/split/split_range.rbs +15 -0
- data/sig/mindee/v2/product/split/split_response.rbs +23 -0
- data/sig/mindee/v2/product/split/split_result.rbs +14 -0
- metadata +80 -3
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'classification_result'
|
|
4
|
+
|
|
5
|
+
module Mindee
|
|
6
|
+
module V2
|
|
7
|
+
module Product
|
|
8
|
+
module Classification
|
|
9
|
+
# The inference result for a classification utility request.
|
|
10
|
+
class ClassificationInference < Mindee::V2::Parsing::BaseInference
|
|
11
|
+
# @return [ClassificationResult] Parsed inference payload.
|
|
12
|
+
attr_reader :result
|
|
13
|
+
|
|
14
|
+
# @param server_response [Hash] Hash representation of the JSON returned by the service.
|
|
15
|
+
def initialize(server_response)
|
|
16
|
+
super
|
|
17
|
+
|
|
18
|
+
@result = ClassificationResult.new(server_response['result'])
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# String representation.
|
|
22
|
+
# @return [String]
|
|
23
|
+
def to_s
|
|
24
|
+
[
|
|
25
|
+
super,
|
|
26
|
+
@result.to_s,
|
|
27
|
+
'',
|
|
28
|
+
].join("\n")
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../../parsing/base_response'
|
|
4
|
+
require_relative 'classification_inference'
|
|
5
|
+
require_relative 'params/classification_parameters'
|
|
6
|
+
|
|
7
|
+
module Mindee
|
|
8
|
+
module V2
|
|
9
|
+
module Product
|
|
10
|
+
module Classification
|
|
11
|
+
# HTTP response wrapper that embeds a V2 Inference.
|
|
12
|
+
class ClassificationResponse < Mindee::V2::Parsing::BaseResponse
|
|
13
|
+
# @return [ClassificationInference] Parsed inference payload.
|
|
14
|
+
attr_reader :inference
|
|
15
|
+
|
|
16
|
+
# @param server_response [Hash] Hash parsed from the API JSON response.
|
|
17
|
+
def initialize(server_response)
|
|
18
|
+
super
|
|
19
|
+
|
|
20
|
+
@inference = ClassificationInference.new(server_response['inference'])
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# String representation.
|
|
24
|
+
# @return [String]
|
|
25
|
+
def to_s
|
|
26
|
+
@inference.to_s
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'classification_classifier'
|
|
4
|
+
|
|
5
|
+
module Mindee
|
|
6
|
+
module V2
|
|
7
|
+
module Product
|
|
8
|
+
module Classification
|
|
9
|
+
# Result of the document classifier inference.
|
|
10
|
+
class ClassificationResult
|
|
11
|
+
# @return [ClassificationClassifier] The document type, as identified on given classification values.
|
|
12
|
+
attr_reader :classification
|
|
13
|
+
|
|
14
|
+
# @param server_response [Hash] Hash representation of the JSON returned by the service.
|
|
15
|
+
def initialize(server_response)
|
|
16
|
+
@classification = ClassificationClassifier.new(server_response['classification'])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# @return [String] String representation.
|
|
20
|
+
def to_s
|
|
21
|
+
"Classification\n==============\n#{@classification}"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mindee
|
|
4
|
+
module V2
|
|
5
|
+
module Product
|
|
6
|
+
module Classification
|
|
7
|
+
module Params
|
|
8
|
+
# Parameters accepted by the classification utility v2 endpoint.
|
|
9
|
+
class ClassificationParameters < Mindee::Input::BaseParameters
|
|
10
|
+
# @return [String] Slug for the endpoint.
|
|
11
|
+
def self.slug
|
|
12
|
+
'classification'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @param [String] model_id ID of the model
|
|
16
|
+
# @param [String, nil] file_alias File alias, if applicable.
|
|
17
|
+
# @param [Array<String>, nil] webhook_ids List of webhook IDs to propagate the API response to.
|
|
18
|
+
# @param [Hash, nil] polling_options Options for polling. Set only if having timeout issues.
|
|
19
|
+
# @param [Boolean, nil] close_file Whether to close the file after parsing.
|
|
20
|
+
def initialize(
|
|
21
|
+
model_id,
|
|
22
|
+
file_alias: nil,
|
|
23
|
+
webhook_ids: nil,
|
|
24
|
+
polling_options: nil,
|
|
25
|
+
close_file: true
|
|
26
|
+
)
|
|
27
|
+
super
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Loads the parameters from a Hash.
|
|
31
|
+
# @param [Hash] params Parameters to provide as a hash.
|
|
32
|
+
# @return [ClassificationParameters]
|
|
33
|
+
def self.from_hash(params: {})
|
|
34
|
+
ClassificationParameters.new(
|
|
35
|
+
params.fetch(:model_id),
|
|
36
|
+
file_alias: params.fetch(:file_alias, nil),
|
|
37
|
+
webhook_ids: params.fetch(:webhook_ids, nil),
|
|
38
|
+
close_file: params.fetch(:close_file, true)
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'crop_response'
|
|
4
|
+
require_relative 'params/crop_parameters'
|
|
5
|
+
|
|
6
|
+
module Mindee
|
|
7
|
+
module V2
|
|
8
|
+
module Product
|
|
9
|
+
module Crop
|
|
10
|
+
# Crop product.
|
|
11
|
+
class Crop < BaseProduct
|
|
12
|
+
@slug = 'crop'
|
|
13
|
+
@params_type = Mindee::V2::Product::Crop::Params::CropParameters
|
|
14
|
+
@response_type = Mindee::V2::Product::Crop::CropResponse
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'crop_result'
|
|
4
|
+
|
|
5
|
+
module Mindee
|
|
6
|
+
module V2
|
|
7
|
+
module Product
|
|
8
|
+
module Crop
|
|
9
|
+
# The inference result for a crop utility request.
|
|
10
|
+
class CropInference < Mindee::V2::Parsing::BaseInference
|
|
11
|
+
# @return [CropResult] Parsed inference payload.
|
|
12
|
+
attr_reader :result
|
|
13
|
+
|
|
14
|
+
# @param server_response [Hash] Hash representation of the JSON returned by the service.
|
|
15
|
+
def initialize(server_response)
|
|
16
|
+
super
|
|
17
|
+
|
|
18
|
+
@result = CropResult.new(server_response['result'])
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# String representation.
|
|
22
|
+
# @return [String]
|
|
23
|
+
def to_s
|
|
24
|
+
[
|
|
25
|
+
super,
|
|
26
|
+
@result.to_s,
|
|
27
|
+
'',
|
|
28
|
+
].join("\n")
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mindee
|
|
4
|
+
module V2
|
|
5
|
+
module Product
|
|
6
|
+
module Crop
|
|
7
|
+
# Result of a cropped document region.
|
|
8
|
+
class CropItem
|
|
9
|
+
# @return [String] Type or classification of the detected object.
|
|
10
|
+
attr_reader :object_type
|
|
11
|
+
# @return [Parsing::V2::Field::FieldLocation] Coordinates of the detected object on the document.
|
|
12
|
+
attr_reader :location
|
|
13
|
+
|
|
14
|
+
# @param server_response [Hash] Hash representation of the JSON returned by the service.
|
|
15
|
+
def initialize(server_response)
|
|
16
|
+
@object_type = server_response['object_type']
|
|
17
|
+
@location = Mindee::Parsing::V2::Field::FieldLocation.new(server_response['location'])
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# String representation.
|
|
21
|
+
# @return [String]
|
|
22
|
+
def to_s
|
|
23
|
+
"* :Location: #{location}\n :Object Type: #{object_type}"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../../parsing/base_response'
|
|
4
|
+
require_relative 'params/crop_parameters'
|
|
5
|
+
require_relative 'crop_inference'
|
|
6
|
+
|
|
7
|
+
module Mindee
|
|
8
|
+
module V2
|
|
9
|
+
module Product
|
|
10
|
+
module Crop
|
|
11
|
+
# HTTP response wrapper that embeds a V2 Inference.
|
|
12
|
+
class CropResponse < Mindee::V2::Parsing::BaseResponse
|
|
13
|
+
# @return [CropInference] Parsed inference payload.
|
|
14
|
+
attr_reader :inference
|
|
15
|
+
|
|
16
|
+
# @param server_response [Hash] Hash parsed from the API JSON response.
|
|
17
|
+
def initialize(server_response)
|
|
18
|
+
super
|
|
19
|
+
|
|
20
|
+
@inference = CropInference.new(server_response['inference'])
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# String representation.
|
|
24
|
+
# @return [String]
|
|
25
|
+
def to_s
|
|
26
|
+
@inference.to_s
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'crop_item'
|
|
4
|
+
|
|
5
|
+
module Mindee
|
|
6
|
+
module V2
|
|
7
|
+
module Product
|
|
8
|
+
module Crop
|
|
9
|
+
# Result of a crop utility inference.
|
|
10
|
+
class CropResult
|
|
11
|
+
# @return [Array<Cropitem>] List of results of cropped document regions.
|
|
12
|
+
attr_reader :crops
|
|
13
|
+
|
|
14
|
+
# @param server_response [Hash] Hash representation of the JSON returned by the service.
|
|
15
|
+
def initialize(server_response)
|
|
16
|
+
@crops = if server_response.key?('crops')
|
|
17
|
+
server_response['crops'].map do |crop|
|
|
18
|
+
CropItem.new(crop)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# String representation.
|
|
24
|
+
# @return [String]
|
|
25
|
+
def to_s
|
|
26
|
+
crops_str = @crops.join("\n")
|
|
27
|
+
|
|
28
|
+
"Crops\n=====\n#{crops_str}"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mindee
|
|
4
|
+
module V2
|
|
5
|
+
module Product
|
|
6
|
+
module Crop
|
|
7
|
+
module Params
|
|
8
|
+
# Parameters accepted by the crop utility v2 endpoint.
|
|
9
|
+
class CropParameters < Mindee::Input::BaseParameters
|
|
10
|
+
# @return [String] Slug for the endpoint.
|
|
11
|
+
def self.slug
|
|
12
|
+
'crop'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @param [String] model_id ID of the model
|
|
16
|
+
# @param [String, nil] file_alias File alias, if applicable.
|
|
17
|
+
# @param [Array<String>, nil] webhook_ids List of webhook IDs to propagate the API response to.
|
|
18
|
+
# @param [Hash, nil] polling_options Options for polling. Set only if having timeout issues.
|
|
19
|
+
# @param [Boolean, nil] close_file Whether to close the file after parsing.
|
|
20
|
+
def initialize(
|
|
21
|
+
model_id,
|
|
22
|
+
file_alias: nil,
|
|
23
|
+
webhook_ids: nil,
|
|
24
|
+
polling_options: nil,
|
|
25
|
+
close_file: true
|
|
26
|
+
)
|
|
27
|
+
super
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Loads the parameters from a Hash.
|
|
31
|
+
# @param [Hash] params Parameters to provide as a hash.
|
|
32
|
+
# @return [CropParameters]
|
|
33
|
+
def self.from_hash(params: {})
|
|
34
|
+
CropParameters.new(
|
|
35
|
+
params.fetch(:model_id),
|
|
36
|
+
file_alias: params.fetch(:file_alias, nil),
|
|
37
|
+
webhook_ids: params.fetch(:webhook_ids, nil),
|
|
38
|
+
close_file: params.fetch(:close_file, true)
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'extraction_response'
|
|
4
|
+
require_relative 'params/extraction_parameters'
|
|
5
|
+
|
|
6
|
+
module Mindee
|
|
7
|
+
module V2
|
|
8
|
+
module Product
|
|
9
|
+
module Extraction
|
|
10
|
+
# Extraction product.
|
|
11
|
+
# Note: currently a placeholder for the `Inference` class.
|
|
12
|
+
class Extraction < Mindee::Parsing::V2::Inference
|
|
13
|
+
@params_type = Product::Extraction::Params::ExtractionParameters
|
|
14
|
+
@response_type = Product::Extraction::ExtractionResponse
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../../../parsing/v2/inference'
|
|
4
|
+
require_relative 'extraction_result'
|
|
5
|
+
|
|
6
|
+
module Mindee
|
|
7
|
+
module V2
|
|
8
|
+
module Product
|
|
9
|
+
module Extraction
|
|
10
|
+
# Extraction inference.
|
|
11
|
+
class ExtractionInference < Mindee::Parsing::V2::Inference
|
|
12
|
+
# @return [ExtractionResult] Parsed inference payload.
|
|
13
|
+
attr_reader :result
|
|
14
|
+
|
|
15
|
+
# @param server_response [Hash] Hash representation of the JSON returned by the service.
|
|
16
|
+
def initialize(server_response)
|
|
17
|
+
super
|
|
18
|
+
|
|
19
|
+
@result = Mindee::V2::Product::Extraction::ExtractionResult.new(server_response['result'])
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../../../parsing/v2/inference_response'
|
|
4
|
+
require_relative 'extraction_inference'
|
|
5
|
+
|
|
6
|
+
module Mindee
|
|
7
|
+
module V2
|
|
8
|
+
module Product
|
|
9
|
+
module Extraction
|
|
10
|
+
# HTTP response wrapper that embeds a V2 Inference.
|
|
11
|
+
class ExtractionResponse < Mindee::Parsing::V2::InferenceResponse
|
|
12
|
+
# @return [ExtractionInference] Parsed inference payload.
|
|
13
|
+
attr_reader :inference
|
|
14
|
+
|
|
15
|
+
def initialize(server_response)
|
|
16
|
+
super
|
|
17
|
+
@inference = Mindee::V2::Product::Extraction::ExtractionInference.new(server_response['inference'])
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../../../parsing/v2/inference_result'
|
|
4
|
+
|
|
5
|
+
module Mindee
|
|
6
|
+
module V2
|
|
7
|
+
module Product
|
|
8
|
+
module Extraction
|
|
9
|
+
# Result of an extraction utility inference.
|
|
10
|
+
class ExtractionResult < Mindee::Parsing::V2::InferenceResult
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../../../../input/inference_parameters'
|
|
4
|
+
|
|
5
|
+
module Mindee
|
|
6
|
+
module V2
|
|
7
|
+
module Product
|
|
8
|
+
module Extraction
|
|
9
|
+
module Params
|
|
10
|
+
# Parameters accepted by the extraction v2 endpoint.
|
|
11
|
+
# Currently a placeholder for the InferenceParameters class.
|
|
12
|
+
class ExtractionParameters < Input::InferenceParameters
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'ocr_response'
|
|
4
|
+
require_relative 'params/ocr_parameters'
|
|
5
|
+
|
|
6
|
+
module Mindee
|
|
7
|
+
module V2
|
|
8
|
+
module Product
|
|
9
|
+
module Ocr
|
|
10
|
+
# Ocr product.
|
|
11
|
+
class Ocr < BaseProduct
|
|
12
|
+
@slug = 'ocr'
|
|
13
|
+
@params_type = Mindee::V2::Product::Ocr::Params::OcrParameters
|
|
14
|
+
@response_type = Mindee::V2::Product::Ocr::OcrResponse
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'ocr_result'
|
|
4
|
+
|
|
5
|
+
module Mindee
|
|
6
|
+
module V2
|
|
7
|
+
module Product
|
|
8
|
+
module Ocr
|
|
9
|
+
# The inference result for an OCR utility request.
|
|
10
|
+
class OcrInference < Mindee::V2::Parsing::BaseInference
|
|
11
|
+
# @return [OcrResult] Parsed inference payload.
|
|
12
|
+
attr_reader :result
|
|
13
|
+
|
|
14
|
+
# @param server_response [Hash] Hash representation of the JSON returned by the service.
|
|
15
|
+
def initialize(server_response)
|
|
16
|
+
super
|
|
17
|
+
|
|
18
|
+
@result = OcrResult.new(server_response['result'])
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# String representation.
|
|
22
|
+
# @return [String]
|
|
23
|
+
def to_s
|
|
24
|
+
[
|
|
25
|
+
super,
|
|
26
|
+
@result.to_s,
|
|
27
|
+
'',
|
|
28
|
+
].join("\n")
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'ocr_word'
|
|
4
|
+
|
|
5
|
+
module Mindee
|
|
6
|
+
module V2
|
|
7
|
+
module Product
|
|
8
|
+
module Ocr
|
|
9
|
+
# OCR result for a single page.
|
|
10
|
+
class OcrPage
|
|
11
|
+
# @return [Array<OcrWord>] List of words extracted from the document page.
|
|
12
|
+
attr_reader :words
|
|
13
|
+
# @return [String] Full text content extracted from the document page.
|
|
14
|
+
attr_reader :content
|
|
15
|
+
|
|
16
|
+
# @param server_response [Hash] Hash representation of the JSON returned by the service.
|
|
17
|
+
def initialize(server_response)
|
|
18
|
+
@words = server_response['words'].map { |word| OcrWord.new(word) }
|
|
19
|
+
@content = server_response['content']
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# String representation.
|
|
23
|
+
# @return [String]
|
|
24
|
+
def to_s
|
|
25
|
+
ocr_words = "\n"
|
|
26
|
+
ocr_words += @words.map(&:to_s).join("\n\n") if @words&.any?
|
|
27
|
+
"OCR Words\n======#{ocr_words}\n\n:Content: #{@content}"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../../parsing/base_response'
|
|
4
|
+
require_relative 'params/ocr_parameters'
|
|
5
|
+
require_relative 'ocr_inference'
|
|
6
|
+
|
|
7
|
+
module Mindee
|
|
8
|
+
module V2
|
|
9
|
+
module Product
|
|
10
|
+
module Ocr
|
|
11
|
+
# HTTP response wrapper that embeds a V2 Inference.
|
|
12
|
+
class OcrResponse < Mindee::V2::Parsing::BaseResponse
|
|
13
|
+
# @return [OcrInference] Parsed inference payload.
|
|
14
|
+
attr_reader :inference
|
|
15
|
+
|
|
16
|
+
# @param server_response [Hash] Hash parsed from the API JSON response.
|
|
17
|
+
def initialize(server_response)
|
|
18
|
+
super
|
|
19
|
+
|
|
20
|
+
@inference = OcrInference.new(server_response['inference'])
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# String representation.
|
|
24
|
+
# @return [String]
|
|
25
|
+
def to_s
|
|
26
|
+
@inference.to_s
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'ocr_page'
|
|
4
|
+
|
|
5
|
+
module Mindee
|
|
6
|
+
module V2
|
|
7
|
+
module Product
|
|
8
|
+
module Ocr
|
|
9
|
+
# Result of a ocr utility inference.
|
|
10
|
+
class OcrResult
|
|
11
|
+
# @return [Array<OcrPage>] List of OCR results for each page in the document.
|
|
12
|
+
attr_reader :pages
|
|
13
|
+
|
|
14
|
+
# @param server_response [Hash] Hash representation of the JSON returned by the service.
|
|
15
|
+
def initialize(server_response)
|
|
16
|
+
@pages = if server_response.key?('pages')
|
|
17
|
+
server_response['pages'].map do |pages|
|
|
18
|
+
OcrPage.new(pages)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# String representation.
|
|
24
|
+
# @return [String]
|
|
25
|
+
def to_s
|
|
26
|
+
pages_str = @pages.join("\n")
|
|
27
|
+
|
|
28
|
+
"Pages\n======\n#{pages_str}"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mindee
|
|
4
|
+
module V2
|
|
5
|
+
module Product
|
|
6
|
+
module Ocr
|
|
7
|
+
# OCR result for a single word extracted from the document page.
|
|
8
|
+
class OcrWord
|
|
9
|
+
# @return [String] Text content of the word.
|
|
10
|
+
attr_reader :content
|
|
11
|
+
# @return [Mindee::Geometry::Polygon] Position information as a list of points in clockwise order.
|
|
12
|
+
attr_reader :polygon
|
|
13
|
+
|
|
14
|
+
# @param server_response [Hash] Hash representation of the JSON returned by the service.
|
|
15
|
+
def initialize(server_response)
|
|
16
|
+
@content = server_response['content']
|
|
17
|
+
@polygon = Mindee::Geometry::Polygon.new(server_response['polygon'])
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# String representation.
|
|
21
|
+
# @return [String]
|
|
22
|
+
def to_s
|
|
23
|
+
@content
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mindee
|
|
4
|
+
module V2
|
|
5
|
+
module Product
|
|
6
|
+
module Ocr
|
|
7
|
+
module Params
|
|
8
|
+
# Parameters accepted by the ocr utility v2 endpoint.
|
|
9
|
+
class OcrParameters < Mindee::Input::BaseParameters
|
|
10
|
+
# @return [String] Slug for the endpoint.
|
|
11
|
+
def self.slug
|
|
12
|
+
'ocr'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @param [String] model_id ID of the model
|
|
16
|
+
# @param [String, nil] file_alias File alias, if applicable.
|
|
17
|
+
# @param [Array<String>, nil] webhook_ids List of webhook IDs to propagate the API response to.
|
|
18
|
+
# @param [Hash, nil] polling_options Options for polling. Set only if having timeout issues.
|
|
19
|
+
# @param [Boolean, nil] close_file Whether to close the file after parsing.
|
|
20
|
+
def initialize(
|
|
21
|
+
model_id,
|
|
22
|
+
file_alias: nil,
|
|
23
|
+
webhook_ids: nil,
|
|
24
|
+
polling_options: nil,
|
|
25
|
+
close_file: true
|
|
26
|
+
)
|
|
27
|
+
super
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Loads the parameters from a Hash.
|
|
31
|
+
# @param [Hash] params Parameters to provide as a hash.
|
|
32
|
+
# @return [OcrParameters]
|
|
33
|
+
def self.from_hash(params: {})
|
|
34
|
+
OcrParameters.new(
|
|
35
|
+
params.fetch(:model_id),
|
|
36
|
+
file_alias: params.fetch(:file_alias, nil),
|
|
37
|
+
webhook_ids: params.fetch(:webhook_ids, nil),
|
|
38
|
+
close_file: params.fetch(:close_file, true)
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|