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
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ module Classification
class ClassificationClassifier
# @return [String] The document type, as identified on given classification values.
attr_reader :document_type
attr_reader :extraction_response

# @param server_response [Hash] Hash representation of the JSON returned by the service.
def initialize(server_response)
@document_type = server_response['document_type']
# rubocop:disable Style/GuardClause
unless server_response['extraction_response'].nil?
@extraction_response = V2::Product::Extraction::ExtractionResponse.new(server_response['extraction_response'])
end
# rubocop:enable Style/GuardClause
end

# @return [String] String representation.
Expand Down
6 changes: 6 additions & 0 deletions lib/mindee/v2/product/crop/crop_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ class CropItem
attr_reader :object_type
# @return [V2::Parsing::Field::FieldLocation] Coordinates of the detected object on the document.
attr_reader :location
attr_reader :extraction_response

# @param server_response [Hash] Hash representation of the JSON returned by the service.
def initialize(server_response)
@object_type = server_response['object_type']
@location = Mindee::V2::Parsing::Field::FieldLocation.new(server_response['location'])
# rubocop:disable Style/GuardClause
unless server_response['extraction_response'].nil?
@extraction_response = V2::Product::Extraction::ExtractionResponse.new(server_response['extraction_response'])
end
# rubocop:enable Style/GuardClause
end

# String representation.
Expand Down
6 changes: 6 additions & 0 deletions lib/mindee/v2/product/split/split_range.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ class SplitRange
attr_reader :page_range
# @return [String] The document type, as identified on given classification values.
attr_reader :document_type
attr_reader :extraction_response

# @param server_response [Hash] Hash representation of the JSON returned by the service.
def initialize(server_response)
@page_range = server_response['page_range']
@document_type = server_response['document_type']
# rubocop:disable Style/GuardClause
unless server_response['extraction_response'].nil?
@extraction_response = V2::Product::Extraction::ExtractionResponse.new(server_response['extraction_response'])
end
# rubocop:enable Style/GuardClause
end

# String representation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Mindee
module Classification
class ClassificationClassifier
attr_reader document_type: String
attr_reader extraction_response: Extraction::ExtractionResponse

def initialize: (Hash[String | Symbol, untyped]) -> void
end
Expand Down
3 changes: 2 additions & 1 deletion sig/mindee/v2/product/crop/crop_item.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ module Mindee
module Product
module Crop
class CropItem
attr_reader extraction_response: Extraction::ExtractionResponse
attr_reader object_type: String
attr_reader location: Mindee::V2::Parsing::Field::FieldLocation
attr_reader location: Parsing::Field::FieldLocation

def initialize: (Hash[String | Symbol, untyped]) -> void

Expand Down
1 change: 1 addition & 0 deletions sig/mindee/v2/product/split/split_range.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Mindee
module Product
module Split
class SplitRange
attr_reader extraction_response: Extraction::ExtractionResponse
attr_reader page_range: Array[Integer]
attr_reader document_type: String

Expand Down
4 changes: 2 additions & 2 deletions spec/v2/file_operations/crop_operation_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def check_findoc_return(findoc_response)

extracted_images.save_all_to_disk(OUTPUT_DIR)

expect(File.size(File.join(OUTPUT_DIR, 'crop_001.jpg'))).to be_between(600_000, 672_913)
expect(File.size(File.join(OUTPUT_DIR, 'crop_002.jpg'))).to be_between(600_000, 675_728)
expect(File.size(File.join(OUTPUT_DIR, 'crop_001.jpg'))).to be_between(560_000, 675_000)
expect(File.size(File.join(OUTPUT_DIR, 'crop_002.jpg'))).to be_between(580_000, 680_000)
end
end
4 changes: 2 additions & 2 deletions spec/v2/product/classification/classification_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

it 'processes classification default sample correctly' do
input_source = Mindee::Input::Source::PathInputSource.new(
File.join(V2_PRODUCT_DATA_DIR, 'classification', 'default_invoice.jpg')
File.join(V2_PRODUCT_DATA_DIR, 'classification', 'default_sample.jpg')
)

params = { model_id: classification_model_id }
Expand All @@ -26,7 +26,7 @@
)

expect(response.inference).not_to be_nil
expect(response.inference.file.name).to eq('default_invoice.jpg')
expect(response.inference.file.name).to eq('default_sample.jpg')
expect(response.inference.result.classification).not_to be_nil
expect(response.inference.result.classification.document_type).to eq('invoice')
end
Expand Down
19 changes: 16 additions & 3 deletions spec/v2/product/classification/classification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
describe Mindee::V2::Product::Classification::Classification, :v2 do
let(:classification_data_dir) { File.join(V2_PRODUCT_DATA_DIR, 'classification') }

it 'parses a single classification properly' do
json_path = File.join(classification_data_dir, 'classification_single.json')
it 'should load a single result' do
json_path = File.join(classification_data_dir, 'default_sample.json')
json_sample = JSON.parse(File.read(json_path))

response = Mindee::V2::Product::Classification::ClassificationResponse.new(json_sample)

expect(response.inference).to be_a(Mindee::V2::Product::Classification::ClassificationInference)
Expand All @@ -20,4 +19,18 @@

expect(response.inference.result.classification.document_type).to eq('invoice')
end

it 'should load a single result with extraction' do
json_path = File.join(classification_data_dir, 'default_sample_extraction.json')
json_sample = JSON.parse(File.read(json_path))
response = Mindee::V2::Product::Classification::ClassificationResponse.new(json_sample)

classification = response.inference.result.classification
expect(classification.document_type).to eq('invoice')

expect(classification.extraction_response).to be_a(Mindee::V2::Product::Extraction::ExtractionResponse)
expect(
classification.extraction_response.inference.result.fields.get_simple_field('customer_name').value
).to eq('Jiro Doi')
end
end
86 changes: 58 additions & 28 deletions spec/v2/product/crop/crop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
describe Mindee::V2::Product::Crop::Crop do
let(:crop_data_dir) { File.join(V2_PRODUCT_DATA_DIR, 'crop') }

it 'parses a single crop properly' do
it 'should load a single result' do
json_path = File.join(crop_data_dir, 'crop_single.json')
rst_path = File.join(crop_data_dir, 'crop_single.rst')

Expand Down Expand Up @@ -37,7 +37,7 @@
expect(response.to_s).to eq(rst_sample)
end

it 'parses multiple crops properly' do
it 'should load multiple results' do
json_path = File.join(crop_data_dir, 'crop_multiple.json')
rst_path = File.join(crop_data_dir, 'crop_multiple.rst')

Expand All @@ -52,35 +52,65 @@
expect(response.inference.result.crops.size).to eq(2)

# First Crop assertions
crop_zero = response.inference.result.crops[0]
expect(crop_zero.location.polygon.size).to eq(4)
expect(crop_zero.location.polygon[0][0]).to eq(0.214)
expect(crop_zero.location.polygon[0][1]).to eq(0.079)
expect(crop_zero.location.polygon[1][0]).to eq(0.476)
expect(crop_zero.location.polygon[1][1]).to eq(0.079)
expect(crop_zero.location.polygon[2][0]).to eq(0.476)
expect(crop_zero.location.polygon[2][1]).to eq(0.979)
expect(crop_zero.location.polygon[3][0]).to eq(0.214)
expect(crop_zero.location.polygon[3][1]).to eq(0.979)

expect(crop_zero.location.page).to eq(0)
expect(crop_zero.object_type).to eq('invoice')
crop0 = response.inference.result.crops[0]
expect(crop0.location.polygon.size).to eq(4)
expect(crop0.location.polygon[0][0]).to eq(0.214)
expect(crop0.location.polygon[0][1]).to eq(0.079)
expect(crop0.location.polygon[1][0]).to eq(0.476)
expect(crop0.location.polygon[1][1]).to eq(0.079)
expect(crop0.location.polygon[2][0]).to eq(0.476)
expect(crop0.location.polygon[2][1]).to eq(0.979)
expect(crop0.location.polygon[3][0]).to eq(0.214)
expect(crop0.location.polygon[3][1]).to eq(0.979)

expect(crop0.location.page).to eq(0)
expect(crop0.object_type).to eq('invoice')

# Second Crop assertions
crop_one = response.inference.result.crops[1]
expect(crop_one.location.polygon.size).to eq(4)
expect(crop_one.location.polygon[0][0]).to eq(0.547)
expect(crop_one.location.polygon[0][1]).to eq(0.15)
expect(crop_one.location.polygon[1][0]).to eq(0.862)
expect(crop_one.location.polygon[1][1]).to eq(0.15)
expect(crop_one.location.polygon[2][0]).to eq(0.862)
expect(crop_one.location.polygon[2][1]).to eq(0.97)
expect(crop_one.location.polygon[3][0]).to eq(0.547)
expect(crop_one.location.polygon[3][1]).to eq(0.97)

expect(crop_one.location.page).to eq(0)
expect(crop_one.object_type).to eq('invoice')
crop1 = response.inference.result.crops[1]
expect(crop1.location.polygon.size).to eq(4)
expect(crop1.location.polygon[0][0]).to eq(0.547)
expect(crop1.location.polygon[0][1]).to eq(0.15)
expect(crop1.location.polygon[1][0]).to eq(0.862)
expect(crop1.location.polygon[1][1]).to eq(0.15)
expect(crop1.location.polygon[2][0]).to eq(0.862)
expect(crop1.location.polygon[2][1]).to eq(0.97)
expect(crop1.location.polygon[3][0]).to eq(0.547)
expect(crop1.location.polygon[3][1]).to eq(0.97)

expect(crop1.location.page).to eq(0)
expect(crop1.object_type).to eq('receipt')

expect(response.to_s).to eq(rst_sample)
end

it 'should load extraction properties' do
json_path = File.join(crop_data_dir, 'default_sample_extraction.json')
json_sample = JSON.parse(File.read(json_path))
response = Mindee::V2::Product::Crop::CropResponse.new(json_sample)

expect(response.inference).to be_a(Mindee::V2::Product::Crop::CropInference)
crops = response.inference.result.crops
expect(response.inference.result.crops.size).to eq(2)

crop0 = crops[0]
expect(crop0.object_type).to eq('receipt')
expect(crop0.location.polygon).not_to be_nil
expect(crop0.location.page).to eq(0)
extraction_response0 = crop0.extraction_response
expect(extraction_response0).not_to be_nil
expect(
extraction_response0.inference.result.fields.get_simple_field('supplier_name').value
).to eq('CHEZ ALAIN MIAM MIAM')

crop1 = crops[1]
expect(crop1.object_type).to eq('receipt')
expect(crop1.location.polygon).not_to be_nil
expect(crop1.location.page).to eq(0)
extraction_response1 = crop1.extraction_response
expect(extraction_response1).not_to be_nil
expect(
extraction_response1.inference.result.fields.get_simple_field('supplier_name').value
).to eq('La cerise sur la pizza')
end
end
64 changes: 46 additions & 18 deletions spec/v2/product/split/split_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,58 @@
it 'parses multiple splits properly' do
json_path = File.join(split_data_dir, 'split_multiple.json')
json_sample = JSON.parse(File.read(json_path))

response = Mindee::V2::Product::Split::SplitResponse.new(json_sample)

expect(response.inference).to be_a(Mindee::V2::Product::Split::SplitInference)
expect(response.inference.result).to be_a(Mindee::V2::Product::Split::SplitResult)
expect(response.inference.result.splits[0]).to be_a(Mindee::V2::Product::Split::SplitRange)
expect(response.inference.result.splits.size).to eq(3)

split_zero = response.inference.result.splits[0]
expect(split_zero.page_range.size).to eq(2)
expect(split_zero.page_range[0]).to eq(0)
expect(split_zero.page_range[1]).to eq(0)
expect(split_zero.document_type).to eq('invoice')

split_one = response.inference.result.splits[1]
expect(split_one.page_range.size).to eq(2)
expect(split_one.page_range[0]).to eq(1)
expect(split_one.page_range[1]).to eq(3)
expect(split_one.document_type).to eq('invoice')

split_two = response.inference.result.splits[2]
expect(split_two.page_range.size).to eq(2)
expect(split_two.page_range[0]).to eq(4)
expect(split_two.page_range[1]).to eq(4)
expect(split_two.document_type).to eq('invoice')
split0 = response.inference.result.splits[0]
expect(split0.page_range.size).to eq(2)
expect(split0.page_range[0]).to eq(0)
expect(split0.page_range[1]).to eq(0)
expect(split0.document_type).to eq('passport')

split1 = response.inference.result.splits[1]
expect(split1.page_range.size).to eq(2)
expect(split1.page_range[0]).to eq(1)
expect(split1.page_range[1]).to eq(3)
expect(split1.document_type).to eq('invoice')

split2 = response.inference.result.splits[2]
expect(split2.page_range.size).to eq(2)
expect(split2.page_range[0]).to eq(4)
expect(split2.page_range[1]).to eq(4)
expect(split2.document_type).to eq('receipt')
end

it 'should load extraction properties' do
json_path = File.join(split_data_dir, 'default_sample_extraction.json')
json_sample = JSON.parse(File.read(json_path))
response = Mindee::V2::Product::Split::SplitResponse.new(json_sample)

expect(response.inference).to be_a(Mindee::V2::Product::Split::SplitInference)

splits = response.inference.result.splits
expect(splits.size).to eq(2)

split0 = splits[0]
expect(split0.document_type).to eq('invoice')
expect(split0.page_range[0]).to eq(0)
extraction_response0 = split0.extraction_response
expect(extraction_response0).not_to be_nil
expect(
extraction_response0.inference.result.fields.get_simple_field('supplier_phone_number').value
).to eq('05 05 44 44 90')

split1 = splits[1]
expect(split1.document_type).to eq('invoice')
expect(split1.page_range[0]).to eq(1)
extraction_response1 = split1.extraction_response
expect(extraction_response1).not_to be_nil
expect(
extraction_response1.inference.result.fields.get_simple_field('supplier_phone_number').value
).to eq('416-555-1212')
end
end
Loading