Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/code_samples/default_v2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ input_source = Mindee::Input::Source::PathInputSource.new(input_path)
# Send for processing
response = mindee_client.enqueue_and_get_inference(
input_source,
inference_params # Note: this parameter can also be provided as a Hash.
inference_params # This parameter can also be provided as a Hash.
)

# Print a brief summary of the parsed data
Expand Down
4 changes: 4 additions & 0 deletions lib/mindee/parsing/v2/raw_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def initialize(server_response)
@pages.push RawTextPage.new(page)
end
end

def to_s
"#{@pages.map(&:to_s).join("\n\n")}\n"
end
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion lib/mindee/parsing/v2/raw_text_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ module Parsing
module V2
# Raw text extracted from a single page.
class RawTextPage
# @return [Boolean] Text content of the page as a single string. '\n' is used to separate lines.
# @return [String] Text content of the page as a single string. '\n' is used to separate lines.
attr_reader :content

# @param server_response [Hash] Raw JSON parsed into a Hash.
def initialize(server_response)
@content = server_response['content']
end

def to_s
@content
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion sig/mindee/parsing/v2/raw_text_page.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Mindee
module Parsing
module V2
class RawTextPage
attr_reader content: string
attr_reader content: String

def initialize: (Hash[String | Symbol, untyped]) -> void
end
Expand Down
11 changes: 9 additions & 2 deletions spec/parsing/v2/inference_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
let(:standard_field_path) { File.join(inference_path, 'standard_field_types.json') }
let(:standard_field_rst_path) { File.join(inference_path, 'standard_field_types.rst') }
let(:location_field_path) { File.join(findoc_path, 'complete_with_coordinates.json') }
let(:raw_text_path) { File.join(inference_path, 'raw_texts.json') }
let(:raw_text_json_path) { File.join(inference_path, 'raw_texts.json') }
let(:raw_text_str_path) { File.join(inference_path, 'raw_texts.txt') }
let(:blank_path) { File.join(findoc_path, 'blank.json') }
let(:complete_path) { File.join(findoc_path, 'complete.json') }

Expand Down Expand Up @@ -268,7 +269,7 @@ def load_standard_fields

describe 'raw_text' do
it 'exposes raw texts' do
response = load_v2_inference(raw_text_path)
response = load_v2_inference(raw_text_json_path)

active_options = response.inference.active_options
expect(active_options).not_to be_nil
Expand All @@ -278,10 +279,16 @@ def load_standard_fields
expect(raw_text).not_to be_nil
expect(raw_text).to be_a(Mindee::Parsing::V2::RawText)

expect(raw_text.to_s).to eq(File.read(raw_text_str_path, encoding: 'UTF-8'))

expect(raw_text.pages.length).to eq(2)
first = raw_text.pages.first
expect(first).to be_a(Mindee::Parsing::V2::RawTextPage)
expect(first.content).to eq('This is the raw text of the first page...')

raw_text.pages.each do |page|
expect(page.content).to be_a(String)
end
end
end

Expand Down