|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'json' |
| 4 | +require 'mindee/parsing' |
| 5 | + |
| 6 | +require_relative '../data' |
| 7 | + |
| 8 | +DIR_CUSTOM_V1 = File.join(DATA_DIR, 'custom', 'response_v1').freeze |
| 9 | + |
| 10 | +describe Mindee::Prediction::CustomV1 do |
| 11 | + context 'A custom document V1' do |
| 12 | + it 'should load an empty document prediction' do |
| 13 | + response = load_json(DIR_CUSTOM_V1, 'empty.json') |
| 14 | + inference = Mindee::Document.new(Mindee::Prediction::CustomV1, response['document']).inference |
| 15 | + expect(inference.product.type).to eq('constructed') |
| 16 | + expect(inference.prediction.fields.length).to eq(10) |
| 17 | + expect(inference.prediction.classifications.length).to eq(1) |
| 18 | + end |
| 19 | + |
| 20 | + it 'should load a complete document prediction' do |
| 21 | + to_string = read_file(DIR_CUSTOM_V1, 'summary_full.rst') |
| 22 | + response = load_json(DIR_CUSTOM_V1, 'complete.json') |
| 23 | + document = Mindee::Document.new(Mindee::Prediction::CustomV1, response['document']) |
| 24 | + expect(document.to_s).to eq(to_string) |
| 25 | + prediction = document.inference.prediction |
| 26 | + |
| 27 | + prediction.fields.each do |field_name, field_data| |
| 28 | + expect(field_name).to be_kind_of(Symbol) |
| 29 | + expect(field_data.values).to be_kind_of(Array) |
| 30 | + expect(field_data.contents_str).to be_kind_of(String) |
| 31 | + end |
| 32 | + |
| 33 | + expect(prediction.fields[:string_all].values.size).to eq(3) |
| 34 | + expect(prediction.fields['string_all']).to be_nil |
| 35 | + expect(prediction.fields[:string_all].contents_str).to eq('Mindee is awesome') |
| 36 | + expect(prediction.fields[:string_all].contents_list).to eq(['Mindee', 'is', 'awesome']) |
| 37 | + |
| 38 | + expect(prediction.classifications[:doc_type].value).to eq('type_b') |
| 39 | + end |
| 40 | + |
| 41 | + it 'should load a complete page 0 prediction' do |
| 42 | + to_string = read_file(DIR_CUSTOM_V1, 'summary_page0.rst') |
| 43 | + response = load_json(DIR_CUSTOM_V1, 'complete.json') |
| 44 | + inference = Mindee::Document.new(Mindee::Prediction::CustomV1, response['document']).inference |
| 45 | + expect(inference.pages[0].prediction.fields[:string_all].contents_str(separator: '_')).to eq('Jenny_is_great') |
| 46 | + expect(inference.pages[0].prediction.fields[:string_all].contents_list).to eq(['Jenny', 'is', 'great']) |
| 47 | + expect(inference.pages[0].to_s).to eq(to_string) |
| 48 | + end |
| 49 | + |
| 50 | + it 'should load a complete page 1 prediction' do |
| 51 | + to_string = read_file(DIR_CUSTOM_V1, 'summary_page1.rst') |
| 52 | + response = load_json(DIR_CUSTOM_V1, 'complete.json') |
| 53 | + inference = Mindee::Document.new(Mindee::Prediction::CustomV1, response['document']).inference |
| 54 | + expect(inference.pages[1].to_s).to eq(to_string) |
| 55 | + end |
| 56 | + end |
| 57 | +end |
0 commit comments