mindee 4.7.0.pre.rc3 → 4.7.1
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/CHANGELOG.md +22 -10
- data/docs/code_samples/default_v2.txt +15 -3
- data/lib/mindee/geometry/polygon.rb +9 -0
- data/lib/mindee/geometry/utils.rb +1 -14
- data/lib/mindee/http/mindee_api_v2.rb +8 -2
- data/lib/mindee/input/inference_parameters.rb +40 -7
- data/lib/mindee/parsing/common/ocr/ocr.rb +1 -1
- data/lib/mindee/parsing/standard/abstract_field.rb +1 -1
- data/lib/mindee/parsing/standard/position_field.rb +1 -1
- data/lib/mindee/parsing/v2/field/base_field.rb +8 -5
- data/lib/mindee/parsing/v2/field/field_confidence.rb +76 -39
- data/lib/mindee/parsing/v2/field/field_location.rb +2 -5
- data/lib/mindee/parsing/v2/field/inference_fields.rb +32 -23
- data/lib/mindee/parsing/v2/field/list_field.rb +27 -36
- data/lib/mindee/parsing/v2/field/object_field.rb +6 -16
- data/lib/mindee/parsing/v2/field/simple_field.rb +6 -1
- data/lib/mindee/parsing/v2/inference.rb +8 -6
- data/lib/mindee/parsing/v2/inference_active_options.rb +42 -0
- data/lib/mindee/parsing/v2/inference_model.rb +12 -0
- data/lib/mindee/parsing/v2/inference_result.rb +4 -15
- data/lib/mindee/parsing/v2/raw_text.rb +11 -7
- data/lib/mindee/parsing/v2/raw_text_page.rb +22 -0
- data/lib/mindee/parsing/v2.rb +2 -1
- data/lib/mindee/version.rb +1 -1
- data/sig/mindee/geometry/polygon.rbs +1 -0
- data/sig/mindee/input/inference_parameters.rbs +6 -0
- data/sig/mindee/parsing/v2/field/field_confidence.rbs +9 -6
- data/sig/mindee/parsing/v2/field/field_location.rbs +2 -2
- data/sig/mindee/parsing/v2/field/inference_fields.rbs +3 -2
- data/sig/mindee/parsing/v2/field/list_field.rbs +3 -1
- data/sig/mindee/parsing/v2/field/object_field.rbs +1 -2
- data/sig/mindee/parsing/v2/field/simple_field.rbs +1 -1
- data/sig/mindee/parsing/v2/inference.rbs +2 -1
- data/sig/mindee/parsing/v2/inference_active_options.rbs +14 -0
- data/sig/mindee/parsing/v2/inference_result.rbs +2 -1
- data/sig/mindee/parsing/v2/raw_text.rbs +2 -2
- data/sig/mindee/parsing/v2/{inference_result_options.rbs → raw_text_page.rbs} +3 -3
- metadata +8 -6
- data/lib/mindee/parsing/v2/inference_result_options.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d580e2dacf0b4846ff5f9d921cfbf53d7c6fe59c8c0c585088812098ab9bd23c
|
4
|
+
data.tar.gz: 494f8a70fd7b52bdebfc702496621e2625a3822ceb4c31233b9c5f85c2d396c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b70d059341d2e80348533ac94a05a12436f5c713e7dd531343945ef8ceecfa7474d0e16d13654583642a15ce1e6afbcdadca3bf6ac570e776d48d49bc8f88cc6
|
7
|
+
data.tar.gz: 1dea5f165d3cda7b6de477fee9b739b1a789d492f28deaa9a3878f9068bab7f5eb5d6a81a3d0bdb6674ae659560ca6912fbba5b1e9a47bc5a32dfa248a4a1b46
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
# Mindee Ruby API Library Changelog
|
2
2
|
|
3
|
+
## v4.7.1 - 2025-09-19
|
4
|
+
### Fixes
|
5
|
+
* :sparkles: add missing `to_s` method on raw_text
|
6
|
+
|
7
|
+
|
8
|
+
## v4.7.0 - 2025-09-18
|
9
|
+
Including RC changes and fixes.
|
10
|
+
### Changes
|
11
|
+
* :sparkles: add support for V2 Mindee API
|
12
|
+
* :sparkles: add missing accessors for PDF fixing options in `LocalInputSource`
|
13
|
+
* :recycle: add many missing internal types
|
14
|
+
### Fixes
|
15
|
+
* :recycle: update existing PDF fixing syntax
|
16
|
+
* :bug: fix for polygon points not correctly initialized
|
17
|
+
* :bug: fix user agent not being able to access version number
|
18
|
+
* :bug: fix invalid types for many V1 features
|
19
|
+
* :bug: fix V1 errors sometimes having the wrong code
|
20
|
+
* :bug: fix many presumably immutable fields having non-readonly parameters
|
21
|
+
* :bug: fix broken `resources` accessor in `ApiRequest` object
|
22
|
+
|
23
|
+
|
3
24
|
## v4.7.0-rc3 - 2025-08-29
|
4
25
|
### Fixes
|
5
26
|
* :bug: fix user agent not being able to access version number
|
@@ -16,7 +37,6 @@
|
|
16
37
|
## v4.7.0-rc1 - 2025-08-13
|
17
38
|
### Changes
|
18
39
|
* :sparkles: add support for client V2 & associated features
|
19
|
-
|
20
40
|
### Fixes
|
21
41
|
* :recycle: add many missing internal types
|
22
42
|
* :bug: fix invalid types for many V1 features
|
@@ -178,7 +198,6 @@
|
|
178
198
|
* :sparkles: add support for cropper Extra
|
179
199
|
* :sparkles: add support for full text Extra
|
180
200
|
* :sparkles: add support for invoice splitter auto-extraction
|
181
|
-
|
182
201
|
### Fixes
|
183
202
|
* :bug: fixed a bug that prevented longer decimals from appearing in the string representation of some objects
|
184
203
|
* :bug: fixed a bug that caused non-table elements to unexpectedly appear truncated when printed to the console
|
@@ -249,7 +268,6 @@
|
|
249
268
|
* :sparkles: add support for EU Driver License V1
|
250
269
|
* :recycle: update existing products
|
251
270
|
* :arrow_up: upgrade test lib
|
252
|
-
|
253
271
|
### Fixes
|
254
272
|
* :memo: add missing default async sample code
|
255
273
|
* :bug: fix rst display issues
|
@@ -277,7 +295,6 @@
|
|
277
295
|
* :sparkles: add support for Carte Grise V1
|
278
296
|
* :sparkles: add page number attributes to doc
|
279
297
|
* :arrow_up: update tests, docs & display format for some products
|
280
|
-
|
281
298
|
### Fixes
|
282
299
|
* :bug: fix page id not working on newer custom models
|
283
300
|
|
@@ -293,7 +310,6 @@
|
|
293
310
|
* :sparkles: add direct access to `raw_http` response
|
294
311
|
* :memo: upgrade reference & guide documentation
|
295
312
|
* :test_tube: **EXPERIMENTAL** add PDF repair option
|
296
|
-
|
297
313
|
### Fixes
|
298
314
|
* :bug: fix display issues with `PositionField`
|
299
315
|
|
@@ -308,7 +324,6 @@
|
|
308
324
|
* :sparkles: add support for US Driver License
|
309
325
|
* :recycle: update unit tests & dependencies
|
310
326
|
* :arrow_up: update Bank Checks (#46)
|
311
|
-
|
312
327
|
### Fixes
|
313
328
|
* :bug: fix `all_words` display (#47)
|
314
329
|
* :bug: fix empty `position_field` (#47)
|
@@ -323,7 +338,6 @@
|
|
323
338
|
* :recycle: harmonize naming with other client libraries
|
324
339
|
* :art: moved most parsing modules into their own respective modules
|
325
340
|
* :art: separated common, standard & custom parsing features into their own modules
|
326
|
-
|
327
341
|
### Changes
|
328
342
|
* :sparkles: add support for asynchronous endpoints
|
329
343
|
* :sparkles: add support for Invoice Splitter V1
|
@@ -337,7 +351,6 @@
|
|
337
351
|
* :pencil2: document all previously non-documented class
|
338
352
|
* :recycle: match file hierarchy with module nesting
|
339
353
|
* :recycle: rewrite tutorials to match new syntax
|
340
|
-
|
341
354
|
### Fixes
|
342
355
|
* :bug: fix: pages now use the proper `orientation` property
|
343
356
|
* :zap: optimize: only a single endpoint is now created on document upload
|
@@ -374,8 +387,7 @@
|
|
374
387
|
* :boom: it should be up to the user to handle API errors
|
375
388
|
* :wastebasket: remove deprecated APIs
|
376
389
|
* :recycle: refactor CLI tool
|
377
|
-
|
378
|
-
### Additions
|
390
|
+
### Changes
|
379
391
|
* :sparkles: add support for Invoice v4.1 and Receipt v4.1
|
380
392
|
* :sparkles: add EU license plates
|
381
393
|
* :sparkles: add shipping containers support
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'mindee'
|
2
4
|
|
3
5
|
input_path = '/path/to/the/file.ext'
|
@@ -11,8 +13,18 @@ mindee_client = Mindee::ClientV2.new(api_key: api_key)
|
|
11
13
|
inference_params = Mindee::Input::InferenceParameters.new(
|
12
14
|
# ID of the model, required.
|
13
15
|
model_id,
|
14
|
-
|
15
|
-
|
16
|
+
|
17
|
+
# Options: set to `true` or `false` to override defaults
|
18
|
+
|
19
|
+
# Enhance extraction accuracy with Retrieval-Augmented Generation.
|
20
|
+
rag: nil,
|
21
|
+
# Extract the full text content from the document as strings.
|
22
|
+
raw_text: nil,
|
23
|
+
# Calculate bounding box polygons for all fields.
|
24
|
+
polygon: nil,
|
25
|
+
# Boost the precision and accuracy of all extractions.
|
26
|
+
# Calculate confidence scores for all fields.
|
27
|
+
confidence: nil
|
16
28
|
)
|
17
29
|
|
18
30
|
# Load a file from disk
|
@@ -21,7 +33,7 @@ input_source = Mindee::Input::Source::PathInputSource.new(input_path)
|
|
21
33
|
# Send for processing
|
22
34
|
response = mindee_client.enqueue_and_get_inference(
|
23
35
|
input_source,
|
24
|
-
inference_params #
|
36
|
+
inference_params # This parameter can also be provided as a Hash.
|
25
37
|
)
|
26
38
|
|
27
39
|
# Print a brief summary of the parsed data
|
@@ -5,6 +5,15 @@ module Mindee
|
|
5
5
|
module Geometry
|
6
6
|
# Contains any number of vertex coordinates (Points).
|
7
7
|
class Polygon < Array
|
8
|
+
# @param server_response [Hash] Raw server response hash.
|
9
|
+
def initialize(server_response)
|
10
|
+
points = []
|
11
|
+
server_response.map do |point|
|
12
|
+
points << Point.new(point[0], point[1])
|
13
|
+
end
|
14
|
+
super(points)
|
15
|
+
end
|
16
|
+
|
8
17
|
# Get the central point (centroid) of the polygon.
|
9
18
|
# @return [Mindee::Geometry::Point]
|
10
19
|
def centroid
|
@@ -17,19 +17,6 @@ module Mindee
|
|
17
17
|
)
|
18
18
|
end
|
19
19
|
|
20
|
-
# Transform a prediction into a Polygon.
|
21
|
-
# @param prediction [Hash]
|
22
|
-
# @return [Mindee::Geometry::Polygon]
|
23
|
-
def self.polygon_from_prediction(prediction)
|
24
|
-
polygon = Polygon.new
|
25
|
-
return polygon if prediction.nil?
|
26
|
-
|
27
|
-
prediction.each do |point|
|
28
|
-
polygon << Point.new(point[0], point[1])
|
29
|
-
end
|
30
|
-
polygon
|
31
|
-
end
|
32
|
-
|
33
20
|
# Gets the points of a bounding box for a given set of points
|
34
21
|
# @param vertices [Array<Mindee::Geometry::Point>]
|
35
22
|
# @return [Array<Float>]
|
@@ -39,7 +26,7 @@ module Mindee
|
|
39
26
|
[x_coords.min, y_coords.min, x_coords.max, y_coords.max]
|
40
27
|
end
|
41
28
|
|
42
|
-
# Creates the bounding
|
29
|
+
# Creates the bounding box for a given set of points
|
43
30
|
# @param vertices [Array<Mindee::Geometry::Point>]
|
44
31
|
# @return [Mindee::Geometry::Quadrilateral]
|
45
32
|
def self.get_bounding_box(vertices)
|
@@ -123,8 +123,14 @@ module Mindee
|
|
123
123
|
file_data, file_metadata = input_source.read_contents(close: params.close_file)
|
124
124
|
[['file', file_data, file_metadata]] # : Array[untyped]
|
125
125
|
end
|
126
|
-
form_data.push
|
127
|
-
|
126
|
+
form_data.push(['model_id', params.model_id])
|
127
|
+
|
128
|
+
# deal with optional features
|
129
|
+
form_data.push(['rag', params.rag.to_s]) unless params.rag.nil?
|
130
|
+
form_data.push(['raw_text', params.raw_text.to_s]) unless params.raw_text.nil?
|
131
|
+
form_data.push(['polygon', params.polygon.to_s]) unless params.polygon.nil?
|
132
|
+
form_data.push(['confidence', params.confidence.to_s]) unless params.confidence.nil?
|
133
|
+
|
128
134
|
form_data.push ['file_alias', params.file_alias] if params.file_alias
|
129
135
|
unless params.webhook_ids.nil? || params.webhook_ids.empty?
|
130
136
|
form_data.push ['webhook_ids', params.webhook_ids.join(',')]
|
@@ -7,9 +7,21 @@ module Mindee
|
|
7
7
|
# @return [String] ID of the model (required).
|
8
8
|
attr_reader :model_id
|
9
9
|
|
10
|
-
# @return [Boolean, nil]
|
10
|
+
# @return [Boolean, nil] Enhance extraction accuracy with Retrieval-Augmented Generation.
|
11
11
|
attr_reader :rag
|
12
12
|
|
13
|
+
# @return [Boolean, nil] Extract the full text content from the document as strings,
|
14
|
+
# and fill the raw_text` attribute.
|
15
|
+
attr_reader :raw_text
|
16
|
+
|
17
|
+
# @return [Boolean, nil] Calculate bounding box polygons for all fields,
|
18
|
+
# and fill their `locations` attribute.
|
19
|
+
attr_reader :polygon
|
20
|
+
|
21
|
+
# @return [Boolean, nil] Boost the precision and accuracy of all extractions.
|
22
|
+
# Calculate confidence scores for all fields, and fill their confidence attribute.
|
23
|
+
attr_reader :confidence
|
24
|
+
|
13
25
|
# @return [String, nil] Optional alias for the file.
|
14
26
|
attr_reader :file_alias
|
15
27
|
|
@@ -22,21 +34,39 @@ module Mindee
|
|
22
34
|
# @return [Boolean, nil] Whether to close the file after parsing.
|
23
35
|
attr_reader :close_file
|
24
36
|
|
37
|
+
# rubocop:disable Metrics/ParameterLists
|
25
38
|
# @param [String] model_id ID of the model
|
26
|
-
# @param [
|
39
|
+
# @param [nil] rag Whether to enable RAG.
|
40
|
+
# @param [nil] raw_text Whether to enable rax text.
|
41
|
+
# @param [nil] polygon Whether to enable polygons.
|
42
|
+
# @param [nil] confidence Whether to enable confidence scores.
|
27
43
|
# @param [nil] file_alias File alias, if applicable.
|
28
44
|
# @param [nil] webhook_ids
|
29
45
|
# @param [nil] polling_options
|
30
46
|
# @param [TrueClass] close_file
|
31
|
-
def initialize(
|
47
|
+
def initialize(
|
48
|
+
model_id,
|
49
|
+
rag: nil,
|
50
|
+
raw_text: nil,
|
51
|
+
polygon: nil,
|
52
|
+
confidence: nil,
|
53
|
+
file_alias: nil,
|
54
|
+
webhook_ids: nil,
|
55
|
+
polling_options: nil,
|
56
|
+
close_file: true
|
57
|
+
)
|
32
58
|
raise Errors::MindeeInputError, 'Model ID is required.' if model_id.empty? || model_id.nil?
|
33
59
|
|
34
60
|
@model_id = model_id
|
35
|
-
@rag = rag
|
61
|
+
@rag = rag
|
62
|
+
@raw_text = raw_text
|
63
|
+
@polygon = polygon
|
64
|
+
@confidence = confidence
|
36
65
|
@file_alias = file_alias
|
37
66
|
@webhook_ids = webhook_ids || []
|
38
67
|
@polling_options = get_clean_polling_options(polling_options)
|
39
68
|
@close_file = close_file.nil? || close_file
|
69
|
+
# rubocop:enable Metrics/ParameterLists
|
40
70
|
end
|
41
71
|
|
42
72
|
# Validates the parameters for async auto-polling
|
@@ -70,7 +100,10 @@ module Mindee
|
|
70
100
|
end
|
71
101
|
|
72
102
|
model_id = params.fetch(:model_id)
|
73
|
-
rag = params.fetch(:rag,
|
103
|
+
rag = params.fetch(:rag, nil)
|
104
|
+
raw_text = params.fetch(:raw_text, nil)
|
105
|
+
polygon = params.fetch(:polygon, nil)
|
106
|
+
confidence = params.fetch(:confidence, nil)
|
74
107
|
file_alias = params.fetch(:file_alias, nil)
|
75
108
|
webhook_ids = params.fetch(:webhook_ids, [])
|
76
109
|
polling_options_input = params.fetch(:page_options, PollingOptions.new)
|
@@ -83,8 +116,8 @@ module Mindee
|
|
83
116
|
)
|
84
117
|
end
|
85
118
|
close_file = params.fetch(:close_file, true)
|
86
|
-
InferenceParameters.new(model_id, rag: rag,
|
87
|
-
close_file: close_file)
|
119
|
+
InferenceParameters.new(model_id, rag: rag, raw_text: raw_text, polygon: polygon, confidence: confidence,
|
120
|
+
file_alias: file_alias, webhook_ids: webhook_ids, close_file: close_file)
|
88
121
|
end
|
89
122
|
|
90
123
|
private
|
@@ -23,7 +23,7 @@ module Mindee
|
|
23
23
|
def initialize(prediction)
|
24
24
|
@text = prediction['text']
|
25
25
|
@confidence = prediction['confidence']
|
26
|
-
@polygon = Geometry.
|
26
|
+
@polygon = Mindee::Geometry::Polygon.new(prediction['polygon'])
|
27
27
|
@bounding_box = Geometry.get_bounding_box(@polygon) unless @polygon.nil? || @polygon.empty?
|
28
28
|
end
|
29
29
|
|
@@ -21,7 +21,7 @@ module Mindee
|
|
21
21
|
# @param page_id [Integer, nil]
|
22
22
|
def initialize(prediction, page_id)
|
23
23
|
@confidence = prediction['confidence'] if prediction.key?('confidence')
|
24
|
-
@polygon = Geometry.
|
24
|
+
@polygon = Mindee::Geometry::Polygon.new(prediction['polygon']) if prediction.key?('polygon')
|
25
25
|
@bounding_box = Geometry.get_bounding_box(@polygon) unless @polygon.nil? || @polygon.empty?
|
26
26
|
@page_id = page_id || prediction['page_id']
|
27
27
|
end
|
@@ -20,7 +20,7 @@ module Mindee
|
|
20
20
|
# @param page_id [Integer, nil]
|
21
21
|
def initialize(prediction, page_id)
|
22
22
|
unless prediction['polygon'].nil? || prediction['polygon'].empty?
|
23
|
-
@polygon = Geometry.
|
23
|
+
@polygon = Mindee::Geometry::Polygon.new(prediction['polygon'])
|
24
24
|
end
|
25
25
|
@quadrangle = to_quadrilateral(prediction, 'quadrangle')
|
26
26
|
@rectangle = to_quadrilateral(prediction, 'rectangle')
|
@@ -20,13 +20,16 @@ module Mindee
|
|
20
20
|
# @param indent_level [Integer] Level of indentation for rst display.
|
21
21
|
def initialize(raw_prediction, indent_level = 0)
|
22
22
|
@indent_level = indent_level
|
23
|
-
|
24
|
-
@
|
25
|
-
|
23
|
+
confidence = raw_prediction['confidence']
|
24
|
+
@confidence = FieldConfidence.new(confidence) unless confidence.nil? || confidence.empty?
|
25
|
+
|
26
|
+
locations = raw_prediction['locations']
|
27
|
+
@locations = if locations.nil? || locations.empty?
|
28
|
+
[]
|
29
|
+
else
|
30
|
+
locations.map do |location|
|
26
31
|
FieldLocation.new(location)
|
27
32
|
end
|
28
|
-
else
|
29
|
-
[]
|
30
33
|
end
|
31
34
|
end
|
32
35
|
|
@@ -19,70 +19,107 @@ module Mindee
|
|
19
19
|
LOW = 'Low'
|
20
20
|
|
21
21
|
# List of valid values, as frozen strings.
|
22
|
-
VALID_VALUES = [
|
22
|
+
VALID_VALUES = ['Certain', 'High', 'Medium', 'Low'].freeze
|
23
23
|
|
24
24
|
# @param value [String] The confidence level value.
|
25
25
|
# @raise [ArgumentError] If the value is not a valid confidence level.
|
26
26
|
def initialize(value)
|
27
|
-
|
27
|
+
case value
|
28
|
+
when 'Certain' then @value = CERTAIN
|
29
|
+
when 'High' then @value = HIGH
|
30
|
+
when 'Medium' then @value = MEDIUM
|
31
|
+
when 'Low' then @value = LOW
|
32
|
+
else
|
28
33
|
raise ArgumentError,
|
29
|
-
"Invalid confidence level: #{value}. Must be one of: #{VALID_VALUES.join(', ')}"
|
34
|
+
"Invalid confidence level: '#{value}'. Must be one of: #{VALID_VALUES.join(', ')}"
|
30
35
|
end
|
31
36
|
|
32
37
|
@value = value
|
33
38
|
end
|
34
39
|
|
35
|
-
#
|
36
|
-
# @
|
37
|
-
|
38
|
-
|
39
|
-
new(value)
|
40
|
+
# String representation of the confidence level.
|
41
|
+
# @return [String] The confidence level value.
|
42
|
+
def to_s
|
43
|
+
@value
|
40
44
|
end
|
41
45
|
|
42
|
-
#
|
43
|
-
# @return [
|
44
|
-
def
|
45
|
-
@value
|
46
|
+
# String representation of the confidence level.
|
47
|
+
# @return [Integer] The confidence level value as an integer: 1 is LOW, 4 is HIGH.
|
48
|
+
def to_i
|
49
|
+
val_to_i(@value)
|
46
50
|
end
|
47
51
|
|
48
|
-
#
|
49
|
-
# @return [
|
50
|
-
def
|
51
|
-
@value
|
52
|
+
# Inspect method for debugging.
|
53
|
+
# @return [String] Debug representation.
|
54
|
+
def inspect
|
55
|
+
"#<#{self.class.name}:#{@value}>"
|
52
56
|
end
|
53
57
|
|
54
|
-
#
|
55
|
-
#
|
56
|
-
def medium?
|
57
|
-
@value == MEDIUM
|
58
|
-
end
|
58
|
+
# Using 'case' breaks steep ...
|
59
|
+
# rubocop:disable Style/CaseLikeIf
|
59
60
|
|
60
|
-
#
|
61
|
-
# @
|
62
|
-
|
63
|
-
|
61
|
+
# Equality of two FieldConfidence instances.
|
62
|
+
# @param other [String, Integer, FieldConfidence] The other confidence to compare.
|
63
|
+
# @return [Boolean] `true` if they have the same value.
|
64
|
+
def ==(other)
|
65
|
+
if other.is_a?(FieldConfidence)
|
66
|
+
@value == other.value
|
67
|
+
elsif other.is_a?(String)
|
68
|
+
@value == other
|
69
|
+
elsif other.is_a?(Integer)
|
70
|
+
to_i == other
|
71
|
+
else
|
72
|
+
raise ArgumentError, "Invalid type: #{other.class}"
|
73
|
+
end
|
64
74
|
end
|
65
75
|
|
66
|
-
#
|
67
|
-
# @
|
68
|
-
def
|
69
|
-
|
76
|
+
# Greater than or equality of two FieldConfidence instances.
|
77
|
+
# @param other [String, Integer, FieldConfidence] The other confidence to compare.
|
78
|
+
def >=(other)
|
79
|
+
if other.is_a?(FieldConfidence)
|
80
|
+
to_i >= val_to_i(other.value)
|
81
|
+
elsif other.is_a?(String)
|
82
|
+
to_i >= val_to_i(other)
|
83
|
+
elsif other.is_a?(Integer)
|
84
|
+
to_i >= other
|
85
|
+
else
|
86
|
+
raise ArgumentError, "Invalid type: #{other.class}"
|
87
|
+
end
|
70
88
|
end
|
71
89
|
|
72
|
-
#
|
73
|
-
# @param other [FieldConfidence] The other confidence to compare.
|
74
|
-
|
75
|
-
|
76
|
-
|
90
|
+
# less than or equality of two FieldConfidence instances.
|
91
|
+
# # @param other [String, Integer, FieldConfidence] The other confidence to compare.
|
92
|
+
def <=(other)
|
93
|
+
if other.is_a?(FieldConfidence)
|
94
|
+
to_i <= val_to_i(other.value)
|
95
|
+
elsif other.is_a?(String)
|
96
|
+
to_i <= val_to_i(other)
|
97
|
+
elsif other.is_a?(Integer)
|
98
|
+
to_i <= other
|
99
|
+
else
|
100
|
+
raise ArgumentError, "Invalid type: #{other.class}"
|
101
|
+
end
|
77
102
|
end
|
78
103
|
|
79
|
-
#
|
104
|
+
# rubocop:enable Style/CaseLikeIf
|
105
|
+
|
106
|
+
# Aliases for the comparison operators.
|
80
107
|
alias eql? ==
|
108
|
+
alias gteql? >=
|
109
|
+
alias lteql? <=
|
81
110
|
|
82
|
-
|
83
|
-
|
84
|
-
def
|
85
|
-
|
111
|
+
protected
|
112
|
+
|
113
|
+
def val_to_i(value)
|
114
|
+
case value
|
115
|
+
when CERTAIN then 4
|
116
|
+
when HIGH then 3
|
117
|
+
when MEDIUM then 2
|
118
|
+
when LOW then 1
|
119
|
+
else
|
120
|
+
raise ArgumentError,
|
121
|
+
"Invalid confidence level: '#{value}'. Must be one of: #{VALID_VALUES.join(', ')}"
|
122
|
+
end
|
86
123
|
end
|
87
124
|
end
|
88
125
|
end
|
@@ -16,11 +16,8 @@ module Mindee
|
|
16
16
|
|
17
17
|
# @param server_response [Hash] Raw server response hash.
|
18
18
|
def initialize(server_response)
|
19
|
-
|
20
|
-
@
|
21
|
-
|
22
|
-
page_id = server_response['page'] || server_response[:page]
|
23
|
-
@page = page_id.is_a?(Float) || page_id.is_a?(Integer) ? page_id.to_i : nil
|
19
|
+
@polygon = Mindee::Geometry::Polygon.new(server_response['polygon'])
|
20
|
+
@page = server_response['page']
|
24
21
|
end
|
25
22
|
|
26
23
|
# String representation of the polygon (empty string when none).
|
@@ -6,7 +6,8 @@ module Mindee
|
|
6
6
|
module Parsing
|
7
7
|
module V2
|
8
8
|
module Field
|
9
|
-
#
|
9
|
+
# Represents a hash-like collection of inference fields, providing methods for
|
10
|
+
# retrieval and string representation.
|
10
11
|
class InferenceFields < Hash
|
11
12
|
# @return [Integer] Level of indentation for rst display.
|
12
13
|
attr_reader :indent_level
|
@@ -29,23 +30,37 @@ module Mindee
|
|
29
30
|
self[key]
|
30
31
|
end
|
31
32
|
|
32
|
-
#
|
33
|
-
# @param
|
34
|
-
# @return [
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
33
|
+
# Get a field by key and ensure it is a SimpleField.
|
34
|
+
# @param key [String] Field key to retrieve.
|
35
|
+
# @return [SimpleField] The SimpleField.
|
36
|
+
# @raise [TypeError] If the field is not a SimpleField.
|
37
|
+
def get_simple_field(key)
|
38
|
+
field = self[key]
|
39
|
+
raise TypeError, "Field #{key} is not a SimpleField" unless field.is_a?(SimpleField)
|
40
|
+
|
41
|
+
field
|
42
42
|
end
|
43
43
|
|
44
|
-
#
|
45
|
-
# @param
|
46
|
-
# @return [
|
47
|
-
|
48
|
-
|
44
|
+
# Get a field by key and ensure it is a ListField.
|
45
|
+
# @param key [String] Field key to retrieve.
|
46
|
+
# @return [ListField] The ListField.
|
47
|
+
# @raise [TypeError] If the field is not a ListField.
|
48
|
+
def get_list_field(key)
|
49
|
+
field = self[key]
|
50
|
+
raise TypeError, "Field #{key} is not a ListField" unless field.is_a?(ListField)
|
51
|
+
|
52
|
+
field
|
53
|
+
end
|
54
|
+
|
55
|
+
# Get a field by key and ensure it is an ObjectField.
|
56
|
+
# @param key [String] Field key to retrieve.
|
57
|
+
# @return [ObjectField] The ObjectField.
|
58
|
+
# @raise [TypeError] If the field is not an ObjectField.
|
59
|
+
def get_object_field(key)
|
60
|
+
field = self[key]
|
61
|
+
raise TypeError, "Field #{key} is not a ObjectField" unless field.is_a?(ObjectField)
|
62
|
+
|
63
|
+
field
|
49
64
|
end
|
50
65
|
|
51
66
|
# rubocop:disable Metrics/CyclomaticComplexity
|
@@ -64,13 +79,7 @@ module Mindee
|
|
64
79
|
line = "#{padding}:#{field_key}:"
|
65
80
|
|
66
81
|
case (field_value.class.name || '').split('::').last
|
67
|
-
when 'ListField'
|
68
|
-
# Check if ListField has items and they're not empty
|
69
|
-
list_f = field_value # @type var list_f: ListField
|
70
|
-
if defined?(list_f.items) && list_f.items && !list_f.items.empty?
|
71
|
-
line += list_f.to_s
|
72
|
-
end
|
73
|
-
when 'ObjectField'
|
82
|
+
when 'ListField', 'ObjectField'
|
74
83
|
line += field_value.to_s
|
75
84
|
when 'SimpleField'
|
76
85
|
# Check if SimpleField has a non-empty value
|
@@ -8,7 +8,6 @@ module Mindee
|
|
8
8
|
module Field
|
9
9
|
# Represents a field that contains a list of items.
|
10
10
|
class ListField < BaseField
|
11
|
-
include Enumerable
|
12
11
|
# @return [Array<ListField | ObjectField | SimpleField>] Items contained in the list.
|
13
12
|
attr_reader :items
|
14
13
|
|
@@ -29,10 +28,36 @@ module Mindee
|
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
31
|
+
# Return only simple fields.
|
32
|
+
# @return [Array<SimpleField>] Simple fields contained in the list.
|
33
|
+
# @raise [TypeError] If the fields are not SimpleField.
|
34
|
+
def simple_items
|
35
|
+
fields = []
|
36
|
+
@items.each do |item|
|
37
|
+
raise TypeError, "Invalid field type detected: #{item.class}" unless item.is_a?(SimpleField)
|
38
|
+
|
39
|
+
fields << item
|
40
|
+
end
|
41
|
+
fields
|
42
|
+
end
|
43
|
+
|
44
|
+
# Return only object fields.
|
45
|
+
# @return [Array<ObjectField>] Object fields contained in the list.
|
46
|
+
# @raise [TypeError] If the fields are not ObjectField.
|
47
|
+
def object_items
|
48
|
+
fields = []
|
49
|
+
@items.each do |item|
|
50
|
+
raise TypeError, "Invalid field type detected: #{item.class}" unless item.is_a?(ObjectField)
|
51
|
+
|
52
|
+
fields << item
|
53
|
+
end
|
54
|
+
fields
|
55
|
+
end
|
56
|
+
|
32
57
|
# String representation of the list field.
|
33
58
|
# @return [String] Formatted string with bullet points for each item.
|
34
59
|
def to_s
|
35
|
-
return
|
60
|
+
return '' unless @items && !@items.empty?
|
36
61
|
|
37
62
|
parts = ['']
|
38
63
|
@items.each do |item|
|
@@ -47,40 +72,6 @@ module Mindee
|
|
47
72
|
|
48
73
|
parts.join("\n * ")
|
49
74
|
end
|
50
|
-
|
51
|
-
# Check if the list is empty.
|
52
|
-
# @return [Boolean] `true` if the list has no items.
|
53
|
-
def empty?
|
54
|
-
@items.empty?
|
55
|
-
end
|
56
|
-
|
57
|
-
# Get the number of items in the list.
|
58
|
-
# @return [Integer] Number of items.
|
59
|
-
def size
|
60
|
-
@items.size
|
61
|
-
end
|
62
|
-
|
63
|
-
# Get the number of items in the list (alias for size).
|
64
|
-
# @return [Integer] Number of items.
|
65
|
-
def length
|
66
|
-
@items.length
|
67
|
-
end
|
68
|
-
|
69
|
-
# Get an item by index.
|
70
|
-
# @param index [Integer] The index of the item to retrieve.
|
71
|
-
# @return [BaseField, nil] The item at the given index.
|
72
|
-
def [](index)
|
73
|
-
@items[index]
|
74
|
-
end
|
75
|
-
|
76
|
-
# Iterator for Enumerator inheritance.
|
77
|
-
# NOTE: Untyped due to incomplete support in current supported version of RBS.
|
78
|
-
def each(&block)
|
79
|
-
return to_enum(:each) unless block_given?
|
80
|
-
|
81
|
-
@items.each(&block)
|
82
|
-
self
|
83
|
-
end
|
84
75
|
end
|
85
76
|
end
|
86
77
|
end
|
@@ -78,22 +78,12 @@ module Mindee
|
|
78
78
|
out_str
|
79
79
|
end
|
80
80
|
|
81
|
-
#
|
82
|
-
# @param
|
83
|
-
# @return [
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
else
|
88
|
-
super
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# Check if method_missing should handle the method.
|
93
|
-
# @param method_name [Symbol] The method name.
|
94
|
-
# @return [Boolean] `true` if the method should be handled.
|
95
|
-
def respond_to_missing?(method_name, include_private = false)
|
96
|
-
@fields.respond_to?(method_name) || super
|
81
|
+
# Get a field by key and ensure it is a SimpleField.
|
82
|
+
# @param key [String] Field key to retrieve.
|
83
|
+
# @return [SimpleField] The SimpleField.
|
84
|
+
# @raise [TypeError] If the field is not a SimpleField.
|
85
|
+
def get_simple_field(key)
|
86
|
+
@fields.get_simple_field(key)
|
97
87
|
end
|
98
88
|
end
|
99
89
|
end
|
@@ -15,7 +15,12 @@ module Mindee
|
|
15
15
|
# @param indent_level [Integer] Level of indentation for rst display.
|
16
16
|
def initialize(server_response, indent_level = 0)
|
17
17
|
super
|
18
|
-
|
18
|
+
value = server_response['value']
|
19
|
+
@value = if value.is_a?(Integer)
|
20
|
+
value.to_f
|
21
|
+
else
|
22
|
+
value
|
23
|
+
end
|
19
24
|
end
|
20
25
|
|
21
26
|
# String representation of the field value.
|
@@ -3,20 +3,23 @@
|
|
3
3
|
require_relative 'inference_model'
|
4
4
|
require_relative 'inference_file'
|
5
5
|
require_relative 'inference_result'
|
6
|
+
require_relative 'inference_active_options'
|
6
7
|
|
7
8
|
module Mindee
|
8
9
|
module Parsing
|
9
10
|
module V2
|
10
11
|
# Complete data returned by an inference request.
|
11
12
|
class Inference
|
13
|
+
# @return [String] Identifier of the inference (when provided by API).
|
14
|
+
attr_reader :id
|
12
15
|
# @return [InferenceModel] Information about the model used.
|
13
16
|
attr_reader :model
|
14
17
|
# @return [InferenceFile] Information about the processed file.
|
15
18
|
attr_reader :file
|
19
|
+
# @return [InferenceActiveOptions] Options which were activated during the inference.
|
20
|
+
attr_reader :active_options
|
16
21
|
# @return [InferenceResult] Result contents.
|
17
22
|
attr_reader :result
|
18
|
-
# @return [String] Identifier of the inference (when provided by API).
|
19
|
-
attr_reader :id
|
20
23
|
|
21
24
|
# @param server_response [Hash] Hash representation of the JSON returned by the service.
|
22
25
|
def initialize(server_response)
|
@@ -24,6 +27,7 @@ module Mindee
|
|
24
27
|
|
25
28
|
@model = InferenceModel.new(server_response['model'])
|
26
29
|
@file = InferenceFile.new(server_response['file'])
|
30
|
+
@active_options = InferenceActiveOptions.new(server_response['active_options'])
|
27
31
|
@result = InferenceResult.new(server_response['result'])
|
28
32
|
|
29
33
|
@id = server_response['id']
|
@@ -35,11 +39,9 @@ module Mindee
|
|
35
39
|
[
|
36
40
|
'Inference',
|
37
41
|
'#########',
|
38
|
-
|
39
|
-
'=====',
|
40
|
-
":ID: #{@model.id}",
|
41
|
-
'',
|
42
|
+
@model.to_s,
|
42
43
|
@file.to_s,
|
44
|
+
@active_options.to_s,
|
43
45
|
@result.to_s,
|
44
46
|
'',
|
45
47
|
].join("\n")
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mindee
|
4
|
+
module Parsing
|
5
|
+
module V2
|
6
|
+
# Options which were activated during the inference.
|
7
|
+
class InferenceActiveOptions
|
8
|
+
# @return [Boolean] Whether the Raw Text feature was activated.
|
9
|
+
attr_reader :raw_text
|
10
|
+
# @return [Boolean] Whether the polygon feature was activated.
|
11
|
+
attr_reader :polygon
|
12
|
+
# @return [Boolean] Whether the confidence feature was activated.
|
13
|
+
attr_reader :confidence
|
14
|
+
# @return [Boolean] Whether the Retrieval-Augmented Generation feature was activated.
|
15
|
+
attr_reader :rag
|
16
|
+
|
17
|
+
# @param server_response [Hash] Raw JSON parsed into a Hash.
|
18
|
+
def initialize(server_response)
|
19
|
+
@raw_text = server_response['raw_text']
|
20
|
+
@polygon = server_response['polygon']
|
21
|
+
@confidence = server_response['confidence']
|
22
|
+
@rag = server_response['rag']
|
23
|
+
end
|
24
|
+
|
25
|
+
# String representation.
|
26
|
+
# @return [String]
|
27
|
+
def to_s
|
28
|
+
parts = [
|
29
|
+
'Active Options',
|
30
|
+
'==============',
|
31
|
+
":Raw Text: #{@raw_text ? 'True' : 'False'}",
|
32
|
+
":Polygon: #{@polygon ? 'True' : 'False'}",
|
33
|
+
":Confidence: #{@confidence ? 'True' : 'False'}",
|
34
|
+
":RAG: #{@rag ? 'True' : 'False'}",
|
35
|
+
'',
|
36
|
+
]
|
37
|
+
parts.join("\n")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -12,6 +12,18 @@ module Mindee
|
|
12
12
|
def initialize(server_response)
|
13
13
|
@id = server_response['id']
|
14
14
|
end
|
15
|
+
|
16
|
+
# String representation.
|
17
|
+
# @return [String]
|
18
|
+
def to_s
|
19
|
+
parts = [
|
20
|
+
'Model',
|
21
|
+
'=====',
|
22
|
+
":ID: #{@id}",
|
23
|
+
'',
|
24
|
+
]
|
25
|
+
parts.join("\n")
|
26
|
+
end
|
15
27
|
end
|
16
28
|
end
|
17
29
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'field/inference_fields'
|
4
|
-
require_relative '
|
4
|
+
require_relative 'raw_text'
|
5
5
|
|
6
6
|
module Mindee
|
7
7
|
module Parsing
|
@@ -10,8 +10,8 @@ module Mindee
|
|
10
10
|
class InferenceResult
|
11
11
|
# @return [Mindee::Parsing::V2::Field::InferenceFields] Fields produced by the model.
|
12
12
|
attr_reader :fields
|
13
|
-
# @return [Mindee::Parsing::V2::
|
14
|
-
attr_reader :
|
13
|
+
# @return [Mindee::Parsing::V2::RawText, nil] Optional extra data.
|
14
|
+
attr_reader :raw_text
|
15
15
|
|
16
16
|
# @param server_response [Hash] Hash version of the JSON returned by the API.
|
17
17
|
def initialize(server_response)
|
@@ -19,9 +19,7 @@ module Mindee
|
|
19
19
|
|
20
20
|
@fields = Field::InferenceFields.new(server_response['fields'])
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
@options = InferenceResultOptions.new(server_response['options'])
|
22
|
+
@raw_text = server_response['raw_text'] ? RawText.new(server_response['raw_text']) : nil
|
25
23
|
end
|
26
24
|
|
27
25
|
# String representation.
|
@@ -32,15 +30,6 @@ module Mindee
|
|
32
30
|
'======',
|
33
31
|
@fields.to_s,
|
34
32
|
]
|
35
|
-
|
36
|
-
if @options
|
37
|
-
parts += [
|
38
|
-
'Options',
|
39
|
-
'=======',
|
40
|
-
@options.to_s,
|
41
|
-
]
|
42
|
-
end
|
43
|
-
|
44
33
|
parts.join("\n")
|
45
34
|
end
|
46
35
|
end
|
@@ -3,17 +3,21 @@
|
|
3
3
|
module Mindee
|
4
4
|
module Parsing
|
5
5
|
module V2
|
6
|
-
# Raw text extracted from
|
6
|
+
# Raw text extracted from all pages in the document.
|
7
7
|
class RawText
|
8
|
-
# @return [
|
9
|
-
attr_reader :
|
10
|
-
# @return [String] Text content.
|
11
|
-
attr_reader :content
|
8
|
+
# @return [Array[Mindee::Parsing::V2::RawTextPage]] List of pages with their extracted text content.
|
9
|
+
attr_reader :pages
|
12
10
|
|
13
11
|
# @param server_response [Hash] Raw JSON parsed into a Hash.
|
14
12
|
def initialize(server_response)
|
15
|
-
@
|
16
|
-
|
13
|
+
@pages = []
|
14
|
+
server_response.fetch('pages', []).each do |page|
|
15
|
+
@pages.push RawTextPage.new(page)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
"#{@pages.map(&:to_s).join("\n\n")}\n"
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mindee
|
4
|
+
module Parsing
|
5
|
+
module V2
|
6
|
+
# Raw text extracted from a single page.
|
7
|
+
class RawTextPage
|
8
|
+
# @return [String] Text content of the page as a single string. '\n' is used to separate lines.
|
9
|
+
attr_reader :content
|
10
|
+
|
11
|
+
# @param server_response [Hash] Raw JSON parsed into a Hash.
|
12
|
+
def initialize(server_response)
|
13
|
+
@content = server_response['content']
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
@content
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/mindee/parsing/v2.rb
CHANGED
@@ -8,8 +8,9 @@ require_relative 'v2/inference_file'
|
|
8
8
|
require_relative 'v2/inference_model'
|
9
9
|
require_relative 'v2/inference_response'
|
10
10
|
require_relative 'v2/inference_result'
|
11
|
-
require_relative 'v2/
|
11
|
+
require_relative 'v2/inference_active_options'
|
12
12
|
require_relative 'v2/job'
|
13
13
|
require_relative 'v2/job_response'
|
14
14
|
require_relative 'v2/job_webhook'
|
15
15
|
require_relative 'v2/raw_text'
|
16
|
+
require_relative 'v2/raw_text_page'
|
data/lib/mindee/version.rb
CHANGED
@@ -3,15 +3,21 @@ module Mindee
|
|
3
3
|
module Input
|
4
4
|
class InferenceParameters
|
5
5
|
attr_reader close_file: bool
|
6
|
+
attr_reader confidence: bool?
|
6
7
|
attr_reader file_alias: String?
|
7
8
|
attr_reader model_id: String
|
8
9
|
attr_reader polling_options: PollingOptions
|
10
|
+
attr_reader polygon: bool?
|
9
11
|
attr_reader rag: bool?
|
12
|
+
attr_reader raw_text: bool?
|
10
13
|
attr_reader webhook_ids: Array[String]?
|
11
14
|
|
12
15
|
def initialize: (
|
13
16
|
String,
|
14
17
|
?rag: bool?,
|
18
|
+
?raw_text: bool?,
|
19
|
+
?polygon: bool?,
|
20
|
+
?confidence: bool?,
|
15
21
|
?file_alias: String?,
|
16
22
|
?webhook_ids: Array[String]?,
|
17
23
|
?polling_options: Hash[Symbol | String, untyped] | PollingOptions?,
|
@@ -12,14 +12,17 @@ module Mindee
|
|
12
12
|
VALID_VALUES: Array[String]
|
13
13
|
def initialize: (String) -> void
|
14
14
|
def self.from_string: (String) -> FieldConfidence
|
15
|
-
def
|
16
|
-
def high?: -> bool
|
17
|
-
def medium?: -> bool
|
18
|
-
def low?: -> bool
|
15
|
+
def to_i: -> Integer
|
19
16
|
def to_s: -> String
|
20
|
-
def ==: (FieldConfidence) -> bool
|
21
|
-
def eql?: (FieldConfidence) -> bool
|
17
|
+
def ==: (String | Integer | FieldConfidence) -> bool
|
18
|
+
def eql?: (String | Integer | FieldConfidence) -> bool
|
19
|
+
def <=: (String | Integer | FieldConfidence) -> bool
|
20
|
+
def lteql? : (String | Integer | FieldConfidence) -> bool
|
21
|
+
def >=: (String | Integer | FieldConfidence) -> bool
|
22
|
+
def gteql?: (String | Integer | FieldConfidence) -> bool
|
22
23
|
def inspect: -> String
|
24
|
+
|
25
|
+
def val_to_i: (String) -> Integer
|
23
26
|
end
|
24
27
|
end
|
25
28
|
end
|
@@ -4,8 +4,8 @@ module Mindee
|
|
4
4
|
module V2
|
5
5
|
module Field
|
6
6
|
class FieldLocation
|
7
|
-
attr_reader page: Integer
|
8
|
-
attr_reader polygon: Geometry::Polygon
|
7
|
+
attr_reader page: Integer
|
8
|
+
attr_reader polygon: Geometry::Polygon
|
9
9
|
|
10
10
|
def initialize: (Hash[String | Symbol, untyped]) -> void
|
11
11
|
def to_s: -> String
|
@@ -6,11 +6,12 @@ module Mindee
|
|
6
6
|
class InferenceFields < Hash[String, ListField | ObjectField | SimpleField?]
|
7
7
|
attr_reader indent_level: Integer
|
8
8
|
|
9
|
+
def get_list_field: (String) -> ListField
|
10
|
+
def get_simple_field: (String) -> SimpleField
|
11
|
+
def get_object_field: (String) -> ObjectField
|
9
12
|
def logger: () -> Logger
|
10
13
|
def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void
|
11
14
|
def get: (String) -> (ListField | ObjectField | SimpleField?)
|
12
|
-
def method_missing: (Symbol, *untyped) -> (ListField | ObjectField | SimpleField?)
|
13
|
-
def respond_to_missing?: (Symbol, ?bool) -> bool
|
14
15
|
def to_s: (?Integer) -> String
|
15
16
|
end
|
16
17
|
end
|
@@ -6,8 +6,10 @@ module Mindee
|
|
6
6
|
class ListField < BaseField
|
7
7
|
include Enumerable[BaseField]
|
8
8
|
|
9
|
-
attr_reader items: Array[
|
9
|
+
attr_reader items: Array[SimpleField | ObjectField | ListField]
|
10
10
|
def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void
|
11
|
+
def object_items: -> Array[ObjectField]
|
12
|
+
def simple_items: -> Array[SimpleField]
|
11
13
|
def to_s: -> String
|
12
14
|
def empty?: -> bool
|
13
15
|
def size: -> Integer
|
@@ -8,12 +8,11 @@ module Mindee
|
|
8
8
|
class ObjectField < BaseField
|
9
9
|
attr_reader fields: InferenceFields
|
10
10
|
def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void
|
11
|
+
def get_simple_field: (String) -> SimpleField
|
11
12
|
def multi_str: -> String
|
12
|
-
def respond_to_missing?: (Symbol, bool) -> bool
|
13
13
|
def single_str: -> String
|
14
14
|
def to_s: -> String
|
15
15
|
def to_s_from_list: -> String
|
16
|
-
def method_missing: (Symbol, *untyped, untyped) -> (ObjectField?)
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
@@ -4,7 +4,7 @@ module Mindee
|
|
4
4
|
module V2
|
5
5
|
module Field
|
6
6
|
class SimpleField < BaseField
|
7
|
-
attr_reader value: String | Integer | Float | bool
|
7
|
+
attr_reader value: String | Integer | Float | bool | nil
|
8
8
|
|
9
9
|
def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void
|
10
10
|
def to_s: -> String
|
@@ -3,9 +3,10 @@ module Mindee
|
|
3
3
|
module Parsing
|
4
4
|
module V2
|
5
5
|
class Inference
|
6
|
-
attr_reader file: InferenceFile
|
7
6
|
attr_reader id: String
|
8
7
|
attr_reader model: InferenceModel
|
8
|
+
attr_reader file: InferenceFile
|
9
|
+
attr_reader active_options: InferenceActiveOptions
|
9
10
|
attr_reader result: InferenceResult
|
10
11
|
|
11
12
|
def initialize: (Hash[String | Symbol, untyped]) -> void
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Mindee
|
2
|
+
module Parsing
|
3
|
+
module V2
|
4
|
+
class InferenceActiveOptions
|
5
|
+
attr_reader confidence: bool
|
6
|
+
attr_reader polygon: bool
|
7
|
+
attr_reader rag: bool
|
8
|
+
attr_reader raw_text: bool
|
9
|
+
|
10
|
+
def initialize: (Hash[String | Symbol, untyped]) -> void
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -4,7 +4,8 @@ module Mindee
|
|
4
4
|
module V2
|
5
5
|
class InferenceResult
|
6
6
|
attr_reader fields: Field::InferenceFields
|
7
|
-
attr_reader
|
7
|
+
attr_reader raw_text: RawText?
|
8
|
+
|
8
9
|
def initialize: (Hash[String | Symbol, untyped]) -> void
|
9
10
|
def to_s: -> String
|
10
11
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
# lib/mindee/parsing/v2/inference_result_options.rb
|
2
1
|
module Mindee
|
3
2
|
module Parsing
|
4
3
|
module V2
|
5
|
-
class
|
6
|
-
attr_reader
|
4
|
+
class RawTextPage
|
5
|
+
attr_reader content: String
|
6
|
+
|
7
7
|
def initialize: (Hash[String | Symbol, untyped]) -> void
|
8
8
|
end
|
9
9
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mindee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.7.
|
4
|
+
version: 4.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mindee, SA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base64
|
@@ -377,15 +377,16 @@ files:
|
|
377
377
|
- lib/mindee/parsing/v2/field/object_field.rb
|
378
378
|
- lib/mindee/parsing/v2/field/simple_field.rb
|
379
379
|
- lib/mindee/parsing/v2/inference.rb
|
380
|
+
- lib/mindee/parsing/v2/inference_active_options.rb
|
380
381
|
- lib/mindee/parsing/v2/inference_file.rb
|
381
382
|
- lib/mindee/parsing/v2/inference_model.rb
|
382
383
|
- lib/mindee/parsing/v2/inference_response.rb
|
383
384
|
- lib/mindee/parsing/v2/inference_result.rb
|
384
|
-
- lib/mindee/parsing/v2/inference_result_options.rb
|
385
385
|
- lib/mindee/parsing/v2/job.rb
|
386
386
|
- lib/mindee/parsing/v2/job_response.rb
|
387
387
|
- lib/mindee/parsing/v2/job_webhook.rb
|
388
388
|
- lib/mindee/parsing/v2/raw_text.rb
|
389
|
+
- lib/mindee/parsing/v2/raw_text_page.rb
|
389
390
|
- lib/mindee/pdf.rb
|
390
391
|
- lib/mindee/pdf/extracted_pdf.rb
|
391
392
|
- lib/mindee/pdf/pdf_compressor.rb
|
@@ -650,15 +651,16 @@ files:
|
|
650
651
|
- sig/mindee/parsing/v2/field/object_field.rbs
|
651
652
|
- sig/mindee/parsing/v2/field/simple_field.rbs
|
652
653
|
- sig/mindee/parsing/v2/inference.rbs
|
654
|
+
- sig/mindee/parsing/v2/inference_active_options.rbs
|
653
655
|
- sig/mindee/parsing/v2/inference_file.rbs
|
654
656
|
- sig/mindee/parsing/v2/inference_model.rbs
|
655
657
|
- sig/mindee/parsing/v2/inference_response.rbs
|
656
658
|
- sig/mindee/parsing/v2/inference_result.rbs
|
657
|
-
- sig/mindee/parsing/v2/inference_result_options.rbs
|
658
659
|
- sig/mindee/parsing/v2/job.rbs
|
659
660
|
- sig/mindee/parsing/v2/job_response.rbs
|
660
661
|
- sig/mindee/parsing/v2/job_webhook.rbs
|
661
662
|
- sig/mindee/parsing/v2/raw_text.rbs
|
663
|
+
- sig/mindee/parsing/v2/raw_text_page.rbs
|
662
664
|
- sig/mindee/pdf/extracted_pdf.rbs
|
663
665
|
- sig/mindee/pdf/pdf_compressor.rbs
|
664
666
|
- sig/mindee/pdf/pdf_extractor.rbs
|
@@ -858,9 +860,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
858
860
|
version: '3.0'
|
859
861
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
860
862
|
requirements:
|
861
|
-
- - "
|
863
|
+
- - ">="
|
862
864
|
- !ruby/object:Gem::Version
|
863
|
-
version:
|
865
|
+
version: '0'
|
864
866
|
requirements: []
|
865
867
|
rubygems_version: 3.2.33
|
866
868
|
signing_key:
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'raw_text'
|
4
|
-
|
5
|
-
module Mindee
|
6
|
-
module Parsing
|
7
|
-
module V2
|
8
|
-
# Optional data returned alongside an inference.
|
9
|
-
class InferenceResultOptions
|
10
|
-
# @return [Array<RawText>] Collection of raw texts per page.
|
11
|
-
attr_reader :raw_texts
|
12
|
-
|
13
|
-
# @param server_response [Hash] Raw JSON parsed into a Hash.
|
14
|
-
def initialize(server_response)
|
15
|
-
raw = server_response['raw_texts']
|
16
|
-
@raw_texts = raw.is_a?(Array) ? raw.map { |rt| RawText.new(rt) } : []
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|