File tree Expand file tree Collapse file tree 16 files changed +172
-101
lines changed Expand file tree Collapse file tree 16 files changed +172
-101
lines changed Original file line number Diff line number Diff line change 88require_relative 'v2/inference_model'
99require_relative 'v2/inference_response'
1010require_relative 'v2/inference_result'
11- require_relative 'v2/inference_result_options '
11+ require_relative 'v2/inference_active_options '
1212require_relative 'v2/job'
1313require_relative 'v2/job_response'
1414require_relative 'v2/job_webhook'
1515require_relative 'v2/raw_text'
16+ require_relative 'v2/raw_text_page'
Original file line number Diff line number Diff line change 33require_relative 'inference_model'
44require_relative 'inference_file'
55require_relative 'inference_result'
6+ require_relative 'inference_active_options'
67
78module Mindee
89 module Parsing
910 module V2
1011 # Complete data returned by an inference request.
1112 class Inference
13+ # @return [String] Identifier of the inference (when provided by API).
14+ attr_reader :id
1215 # @return [InferenceModel] Information about the model used.
1316 attr_reader :model
1417 # @return [InferenceFile] Information about the processed file.
1518 attr_reader :file
19+ # @return [InferenceActiveOptions] Options which were activated during the inference.
20+ attr_reader :active_options
1621 # @return [InferenceResult] Result contents.
1722 attr_reader :result
18- # @return [String] Identifier of the inference (when provided by API).
19- attr_reader :id
2023
2124 # @param server_response [Hash] Hash representation of the JSON returned by the service.
2225 def initialize ( server_response )
2326 raise ArgumentError , 'server_response must be a Hash' unless server_response . is_a? ( Hash )
2427
2528 @model = InferenceModel . new ( server_response [ 'model' ] )
2629 @file = InferenceFile . new ( server_response [ 'file' ] )
30+ @active_options = InferenceActiveOptions . new ( server_response [ 'active_options' ] )
2731 @result = InferenceResult . new ( server_response [ 'result' ] )
2832
2933 @id = server_response [ 'id' ]
@@ -35,11 +39,9 @@ def to_s
3539 [
3640 'Inference' ,
3741 '#########' ,
38- 'Model' ,
39- '=====' ,
40- ":ID: #{ @model . id } " ,
41- '' ,
42+ @model . to_s ,
4243 @file . to_s ,
44+ @active_options . to_s ,
4345 @result . to_s ,
4446 '' ,
4547 ] . join ( "\n " )
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change @@ -12,6 +12,18 @@ class InferenceModel
1212 def initialize ( server_response )
1313 @id = server_response [ 'id' ]
1414 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
1527 end
1628 end
1729 end
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33require_relative 'field/inference_fields'
4- require_relative 'inference_result_options '
4+ require_relative 'raw_text '
55
66module Mindee
77 module Parsing
@@ -10,18 +10,16 @@ module V2
1010 class InferenceResult
1111 # @return [Mindee::Parsing::V2::Field::InferenceFields] Fields produced by the model.
1212 attr_reader :fields
13- # @return [Mindee::Parsing::V2::InferenceResultOptions , nil] Optional extra data.
14- attr_reader :options
13+ # @return [Mindee::Parsing::V2::RawText , nil] Optional extra data.
14+ attr_reader :raw_text
1515
1616 # @param server_response [Hash] Hash version of the JSON returned by the API.
1717 def initialize ( server_response )
1818 raise ArgumentError , 'server_response must be a Hash' unless server_response . is_a? ( Hash )
1919
2020 @fields = Field ::InferenceFields . new ( server_response [ 'fields' ] )
2121
22- return unless server_response . key? ( 'options' ) && server_response [ 'options' ]
23-
24- @options = InferenceResultOptions . new ( server_response [ 'options' ] )
22+ @raw_text = server_response [ 'raw_text' ] ? RawText . new ( server_response [ 'raw_text' ] ) : nil
2523 end
2624
2725 # String representation.
@@ -32,15 +30,6 @@ def to_s
3230 '======' ,
3331 @fields . to_s ,
3432 ]
35-
36- if @options
37- parts += [
38- 'Options' ,
39- '=======' ,
40- @options . to_s ,
41- ]
42- end
43-
4433 parts . join ( "\n " )
4534 end
4635 end
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 33module Mindee
44 module Parsing
55 module V2
6- # Raw text extracted from a given page .
6+ # Raw text extracted from all pages in the document .
77 class RawText
8- # @return [Integer] Page number where the text was found.
9- attr_reader :page
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
1210
1311 # @param server_response [Hash] Raw JSON parsed into a Hash.
1412 def initialize ( server_response )
15- @page = server_response [ 'page' ]
16- @content = server_response [ 'content' ]
13+ @pages = [ ]
14+ server_response . fetch ( 'pages' , [ ] ) . each do |page |
15+ @pages . push RawTextPage . new ( page )
16+ end
1717 end
1818 end
1919 end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ module Mindee
4+ module Parsing
5+ module V2
6+ # Raw text extracted from a given page.
7+ class RawTextPage
8+ # @return [Boolean] Content of the raw text.
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+ end
16+ end
17+ end
18+ end
Original file line number Diff line number Diff line change @@ -3,9 +3,10 @@ module Mindee
33 module Parsing
44 module V2
55 class Inference
6- attr_reader file: InferenceFile
76 attr_reader id: String
87 attr_reader model: InferenceModel
8+ attr_reader file: InferenceFile
9+ attr_reader active_options: InferenceActiveOptions
910 attr_reader result: InferenceResult
1011
1112 def initialize : (Hash[String | Symbol, untyped ]) -> void
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments