mindee-lite 5.0.0.beta1
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 +7 -0
- data/.editorconfig +24 -0
- data/.gitattributes +14 -0
- data/.gitignore +76 -0
- data/.gitmodules +3 -0
- data/.pre-commit-config.yaml +36 -0
- data/.rubocop.yml +49 -0
- data/.yardopts +4 -0
- data/CHANGELOG.md +515 -0
- data/CODE_OF_CONDUCT.md +129 -0
- data/CONTRIBUTING.md +107 -0
- data/Gemfile +14 -0
- data/LICENSE +21 -0
- data/README.md +42 -0
- data/Rakefile +40 -0
- data/Steepfile +30 -0
- data/bin/console +14 -0
- data/bin/mindee.rb +30 -0
- data/bin/v1/parser.rb +153 -0
- data/bin/v1/products.rb +88 -0
- data/bin/v2/parser.rb +235 -0
- data/bin/v2/products.rb +34 -0
- data/docs/code_samples/bank_account_details_v1.txt +24 -0
- data/docs/code_samples/bank_account_details_v2.txt +24 -0
- data/docs/code_samples/bank_statement_fr_v2_async.txt +24 -0
- data/docs/code_samples/barcode_reader_v1.txt +24 -0
- data/docs/code_samples/cropper_v1.txt +21 -0
- data/docs/code_samples/default.txt +30 -0
- data/docs/code_samples/default_async.txt +29 -0
- data/docs/code_samples/expense_receipts_v5.txt +25 -0
- data/docs/code_samples/expense_receipts_v5_async.txt +24 -0
- data/docs/code_samples/financial_document_v1.txt +25 -0
- data/docs/code_samples/financial_document_v1_async.txt +24 -0
- data/docs/code_samples/idcard_fr_v1.txt +24 -0
- data/docs/code_samples/idcard_fr_v2.txt +24 -0
- data/docs/code_samples/international_id_v2_async.txt +24 -0
- data/docs/code_samples/invoice_splitter_v1_async.txt +24 -0
- data/docs/code_samples/invoices_v4.txt +25 -0
- data/docs/code_samples/invoices_v4_async.txt +24 -0
- data/docs/code_samples/multi_receipts_detector_v1.txt +24 -0
- data/docs/code_samples/passport_v1.txt +24 -0
- data/docs/code_samples/resume_v1_async.txt +24 -0
- data/docs/code_samples/v2_classification.txt +30 -0
- data/docs/code_samples/v2_crop.txt +30 -0
- data/docs/code_samples/v2_extraction.txt +42 -0
- data/docs/code_samples/v2_extraction_webhook.txt +45 -0
- data/docs/code_samples/v2_ocr.txt +30 -0
- data/docs/code_samples/v2_split.txt +30 -0
- data/docs/code_samples/workflow_execution.txt +28 -0
- data/docs/code_samples/workflow_polling.txt +35 -0
- data/examples/auto_invoice_splitter_extraction.rb +48 -0
- data/examples/auto_multi_receipts_detector_extraction.rb +30 -0
- data/lib/mindee/dependency.rb +29 -0
- data/lib/mindee/error/mindee_error.rb +17 -0
- data/lib/mindee/error/mindee_http_error.rb +36 -0
- data/lib/mindee/error/mindee_http_error_v2.rb +45 -0
- data/lib/mindee/error/mindee_http_unknown_error_v2.rb +18 -0
- data/lib/mindee/error/mindee_input_error.rb +30 -0
- data/lib/mindee/error.rb +6 -0
- data/lib/mindee/geometry/min_max.rb +23 -0
- data/lib/mindee/geometry/point.rb +41 -0
- data/lib/mindee/geometry/polygon.rb +37 -0
- data/lib/mindee/geometry/quadrilateral.rb +50 -0
- data/lib/mindee/geometry/utils.rb +88 -0
- data/lib/mindee/geometry.rb +7 -0
- data/lib/mindee/http/.rubocop.yml +7 -0
- data/lib/mindee/http/http_error_handler.rb +106 -0
- data/lib/mindee/http/response_validation.rb +81 -0
- data/lib/mindee/http.rb +3 -0
- data/lib/mindee/image/extracted_image.rb +89 -0
- data/lib/mindee/image/image_compressor.rb +29 -0
- data/lib/mindee/image/image_extractor.rb +118 -0
- data/lib/mindee/image/image_utils.rb +165 -0
- data/lib/mindee/image.rb +6 -0
- data/lib/mindee/input/base_parameters.rb +149 -0
- data/lib/mindee/input/local_response.rb +80 -0
- data/lib/mindee/input/polling_options.rb +26 -0
- data/lib/mindee/input/sources/base64_input_source.rb +31 -0
- data/lib/mindee/input/sources/bytes_input_source.rb +21 -0
- data/lib/mindee/input/sources/file_input_source.rb +20 -0
- data/lib/mindee/input/sources/local_input_source.rb +216 -0
- data/lib/mindee/input/sources/path_input_source.rb +20 -0
- data/lib/mindee/input/sources/url_input_source.rb +130 -0
- data/lib/mindee/input/sources.rb +8 -0
- data/lib/mindee/input.rb +4 -0
- data/lib/mindee/logging/logger.rb +24 -0
- data/lib/mindee/logging.rb +3 -0
- data/lib/mindee/page_options.rb +24 -0
- data/lib/mindee/pdf/extracted_pdf.rb +70 -0
- data/lib/mindee/pdf/pdf_compressor.rb +121 -0
- data/lib/mindee/pdf/pdf_extractor.rb +121 -0
- data/lib/mindee/pdf/pdf_processor.rb +91 -0
- data/lib/mindee/pdf/pdf_tools.rb +201 -0
- data/lib/mindee/pdf.rb +7 -0
- data/lib/mindee/v1/client.rb +490 -0
- data/lib/mindee/v1/extraction/multi_receipts_extractor.rb +32 -0
- data/lib/mindee/v1/extraction.rb +3 -0
- data/lib/mindee/v1/http/.rubocop.yml +7 -0
- data/lib/mindee/v1/http/endpoint.rb +221 -0
- data/lib/mindee/v1/http/workflow_endpoint.rb +93 -0
- data/lib/mindee/v1/http.rb +4 -0
- data/lib/mindee/v1/parsing/common/api_request.rb +38 -0
- data/lib/mindee/v1/parsing/common/api_response.rb +63 -0
- data/lib/mindee/v1/parsing/common/document.rb +86 -0
- data/lib/mindee/v1/parsing/common/execution.rb +78 -0
- data/lib/mindee/v1/parsing/common/execution_file.rb +26 -0
- data/lib/mindee/v1/parsing/common/execution_priority.rb +38 -0
- data/lib/mindee/v1/parsing/common/extras/cropper_extra.rb +32 -0
- data/lib/mindee/v1/parsing/common/extras/extras.rb +62 -0
- data/lib/mindee/v1/parsing/common/extras/full_text_ocr_extra.rb +35 -0
- data/lib/mindee/v1/parsing/common/extras/rag_extra.rb +28 -0
- data/lib/mindee/v1/parsing/common/extras.rb +6 -0
- data/lib/mindee/v1/parsing/common/inference.rb +69 -0
- data/lib/mindee/v1/parsing/common/job.rb +48 -0
- data/lib/mindee/v1/parsing/common/ocr/mvision_v1.rb +52 -0
- data/lib/mindee/v1/parsing/common/ocr/ocr.rb +180 -0
- data/lib/mindee/v1/parsing/common/ocr.rb +3 -0
- data/lib/mindee/v1/parsing/common/orientation.rb +28 -0
- data/lib/mindee/v1/parsing/common/page.rb +49 -0
- data/lib/mindee/v1/parsing/common/prediction.rb +19 -0
- data/lib/mindee/v1/parsing/common/product.rb +26 -0
- data/lib/mindee/v1/parsing/common/workflow_response.rb +30 -0
- data/lib/mindee/v1/parsing/common.rb +15 -0
- data/lib/mindee/v1/parsing/standard/abstract_field.rb +74 -0
- data/lib/mindee/v1/parsing/standard/address_field.rb +51 -0
- data/lib/mindee/v1/parsing/standard/amount_field.rb +28 -0
- data/lib/mindee/v1/parsing/standard/base_field.rb +30 -0
- data/lib/mindee/v1/parsing/standard/boolean_field.rb +29 -0
- data/lib/mindee/v1/parsing/standard/classification_field.rb +18 -0
- data/lib/mindee/v1/parsing/standard/company_registration_field.rb +45 -0
- data/lib/mindee/v1/parsing/standard/date_field.rb +40 -0
- data/lib/mindee/v1/parsing/standard/feature_field.rb +26 -0
- data/lib/mindee/v1/parsing/standard/locale_field.rb +52 -0
- data/lib/mindee/v1/parsing/standard/payment_details_field.rb +44 -0
- data/lib/mindee/v1/parsing/standard/position_field.rb +61 -0
- data/lib/mindee/v1/parsing/standard/string_field.rb +26 -0
- data/lib/mindee/v1/parsing/standard/tax_field.rb +110 -0
- data/lib/mindee/v1/parsing/standard.rb +15 -0
- data/lib/mindee/v1/parsing/universal/universal_list_field.rb +60 -0
- data/lib/mindee/v1/parsing/universal/universal_object_field.rb +123 -0
- data/lib/mindee/v1/parsing/universal.rb +4 -0
- data/lib/mindee/v1/parsing.rb +5 -0
- data/lib/mindee/v1/product/.rubocop.yml +12 -0
- data/lib/mindee/v1/product/barcode_reader/barcode_reader_v1.rb +47 -0
- data/lib/mindee/v1/product/barcode_reader/barcode_reader_v1_document.rb +47 -0
- data/lib/mindee/v1/product/barcode_reader/barcode_reader_v1_page.rb +38 -0
- data/lib/mindee/v1/product/cropper/cropper_v1.rb +47 -0
- data/lib/mindee/v1/product/cropper/cropper_v1_document.rb +15 -0
- data/lib/mindee/v1/product/cropper/cropper_v1_page.rb +55 -0
- data/lib/mindee/v1/product/financial_document/financial_document_v1.rb +47 -0
- data/lib/mindee/v1/product/financial_document/financial_document_v1_document.rb +329 -0
- data/lib/mindee/v1/product/financial_document/financial_document_v1_line_item.rb +124 -0
- data/lib/mindee/v1/product/financial_document/financial_document_v1_line_items.rb +64 -0
- data/lib/mindee/v1/product/financial_document/financial_document_v1_page.rb +38 -0
- data/lib/mindee/v1/product/fr/bank_account_details/bank_account_details_v1.rb +49 -0
- data/lib/mindee/v1/product/fr/bank_account_details/bank_account_details_v1_document.rb +49 -0
- data/lib/mindee/v1/product/fr/bank_account_details/bank_account_details_v1_page.rb +40 -0
- data/lib/mindee/v1/product/fr/bank_account_details/bank_account_details_v2.rb +49 -0
- data/lib/mindee/v1/product/fr/bank_account_details/bank_account_details_v2_bban.rb +63 -0
- data/lib/mindee/v1/product/fr/bank_account_details/bank_account_details_v2_document.rb +60 -0
- data/lib/mindee/v1/product/fr/bank_account_details/bank_account_details_v2_page.rb +40 -0
- data/lib/mindee/v1/product/fr/bank_statement/bank_statement_v2.rb +49 -0
- data/lib/mindee/v1/product/fr/bank_statement/bank_statement_v2_document.rb +169 -0
- data/lib/mindee/v1/product/fr/bank_statement/bank_statement_v2_page.rb +40 -0
- data/lib/mindee/v1/product/fr/bank_statement/bank_statement_v2_transaction.rb +78 -0
- data/lib/mindee/v1/product/fr/bank_statement/bank_statement_v2_transactions.rb +56 -0
- data/lib/mindee/v1/product/fr/id_card/id_card_v1.rb +49 -0
- data/lib/mindee/v1/product/fr/id_card/id_card_v1_document.rb +106 -0
- data/lib/mindee/v1/product/fr/id_card/id_card_v1_page.rb +57 -0
- data/lib/mindee/v1/product/fr/id_card/id_card_v2.rb +49 -0
- data/lib/mindee/v1/product/fr/id_card/id_card_v2_document.rb +143 -0
- data/lib/mindee/v1/product/fr/id_card/id_card_v2_page.rb +65 -0
- data/lib/mindee/v1/product/international_id/international_id_v2.rb +47 -0
- data/lib/mindee/v1/product/international_id/international_id_v2_document.rb +164 -0
- data/lib/mindee/v1/product/international_id/international_id_v2_page.rb +38 -0
- data/lib/mindee/v1/product/invoice/invoice_v4.rb +47 -0
- data/lib/mindee/v1/product/invoice/invoice_v4_document.rb +300 -0
- data/lib/mindee/v1/product/invoice/invoice_v4_line_item.rb +124 -0
- data/lib/mindee/v1/product/invoice/invoice_v4_line_items.rb +64 -0
- data/lib/mindee/v1/product/invoice/invoice_v4_page.rb +38 -0
- data/lib/mindee/v1/product/invoice_splitter/invoice_splitter_v1.rb +47 -0
- data/lib/mindee/v1/product/invoice_splitter/invoice_splitter_v1_document.rb +66 -0
- data/lib/mindee/v1/product/invoice_splitter/invoice_splitter_v1_invoice_page_group.rb +58 -0
- data/lib/mindee/v1/product/invoice_splitter/invoice_splitter_v1_invoice_page_groups.rb +50 -0
- data/lib/mindee/v1/product/invoice_splitter/invoice_splitter_v1_page.rb +38 -0
- data/lib/mindee/v1/product/multi_receipts_detector/multi_receipts_detector_v1.rb +47 -0
- data/lib/mindee/v1/product/multi_receipts_detector/multi_receipts_detector_v1_document.rb +38 -0
- data/lib/mindee/v1/product/multi_receipts_detector/multi_receipts_detector_v1_page.rb +38 -0
- data/lib/mindee/v1/product/passport/passport_v1.rb +47 -0
- data/lib/mindee/v1/product/passport/passport_v1_document.rb +112 -0
- data/lib/mindee/v1/product/passport/passport_v1_page.rb +38 -0
- data/lib/mindee/v1/product/receipt/receipt_v5.rb +47 -0
- data/lib/mindee/v1/product/receipt/receipt_v5_document.rb +187 -0
- data/lib/mindee/v1/product/receipt/receipt_v5_line_item.rb +88 -0
- data/lib/mindee/v1/product/receipt/receipt_v5_line_items.rb +56 -0
- data/lib/mindee/v1/product/receipt/receipt_v5_page.rb +38 -0
- data/lib/mindee/v1/product/resume/resume_v1.rb +47 -0
- data/lib/mindee/v1/product/resume/resume_v1_certificate.rb +82 -0
- data/lib/mindee/v1/product/resume/resume_v1_certificates.rb +60 -0
- data/lib/mindee/v1/product/resume/resume_v1_document.rb +340 -0
- data/lib/mindee/v1/product/resume/resume_v1_education.rb +106 -0
- data/lib/mindee/v1/product/resume/resume_v1_educations.rb +66 -0
- data/lib/mindee/v1/product/resume/resume_v1_language.rb +66 -0
- data/lib/mindee/v1/product/resume/resume_v1_languages.rb +56 -0
- data/lib/mindee/v1/product/resume/resume_v1_page.rb +38 -0
- data/lib/mindee/v1/product/resume/resume_v1_professional_experience.rb +122 -0
- data/lib/mindee/v1/product/resume/resume_v1_professional_experiences.rb +70 -0
- data/lib/mindee/v1/product/resume/resume_v1_social_networks_url.rb +66 -0
- data/lib/mindee/v1/product/resume/resume_v1_social_networks_urls.rb +56 -0
- data/lib/mindee/v1/product/universal/universal.rb +48 -0
- data/lib/mindee/v1/product/universal/universal_document.rb +35 -0
- data/lib/mindee/v1/product/universal/universal_page.rb +54 -0
- data/lib/mindee/v1/product/universal/universal_prediction.rb +128 -0
- data/lib/mindee/v1/product.rb +18 -0
- data/lib/mindee/v1.rb +7 -0
- data/lib/mindee/v2/client.rb +132 -0
- data/lib/mindee/v2/file_operation/crop.rb +51 -0
- data/lib/mindee/v2/file_operation/crop_files.rb +25 -0
- data/lib/mindee/v2/file_operation/split.rb +37 -0
- data/lib/mindee/v2/file_operation/split_files.rb +25 -0
- data/lib/mindee/v2/file_operation.rb +6 -0
- data/lib/mindee/v2/http/.rubocop.yml +7 -0
- data/lib/mindee/v2/http/api_v2_settings.rb +65 -0
- data/lib/mindee/v2/http/mindee_api_v2.rb +230 -0
- data/lib/mindee/v2/http.rb +4 -0
- data/lib/mindee/v2/parsing/base_inference.rb +44 -0
- data/lib/mindee/v2/parsing/base_response.rb +15 -0
- data/lib/mindee/v2/parsing/common_response.rb +20 -0
- data/lib/mindee/v2/parsing/error_item.rb +21 -0
- data/lib/mindee/v2/parsing/error_response.rb +51 -0
- data/lib/mindee/v2/parsing/field/base_field.rb +63 -0
- data/lib/mindee/v2/parsing/field/field_confidence.rb +128 -0
- data/lib/mindee/v2/parsing/field/field_location.rb +33 -0
- data/lib/mindee/v2/parsing/field/inference_fields.rb +105 -0
- data/lib/mindee/v2/parsing/field/list_field.rb +79 -0
- data/lib/mindee/v2/parsing/field/object_field.rb +138 -0
- data/lib/mindee/v2/parsing/field/simple_field.rb +60 -0
- data/lib/mindee/v2/parsing/field.rb +9 -0
- data/lib/mindee/v2/parsing/inference_active_options.rb +67 -0
- data/lib/mindee/v2/parsing/inference_file.rb +38 -0
- data/lib/mindee/v2/parsing/inference_job.rb +25 -0
- data/lib/mindee/v2/parsing/inference_model.rb +30 -0
- data/lib/mindee/v2/parsing/job.rb +93 -0
- data/lib/mindee/v2/parsing/job_response.rb +30 -0
- data/lib/mindee/v2/parsing/job_webhook.rb +59 -0
- data/lib/mindee/v2/parsing/rag_metadata.rb +17 -0
- data/lib/mindee/v2/parsing/raw_text.rb +27 -0
- data/lib/mindee/v2/parsing/raw_text_page.rb +24 -0
- data/lib/mindee/v2/parsing/search/pagination_metadata.rb +44 -0
- data/lib/mindee/v2/parsing/search/search_model.rb +38 -0
- data/lib/mindee/v2/parsing/search/search_models.rb +34 -0
- data/lib/mindee/v2/parsing/search/search_response.rb +38 -0
- data/lib/mindee/v2/parsing/search.rb +6 -0
- data/lib/mindee/v2/parsing.rb +16 -0
- data/lib/mindee/v2/product/base_product.rb +28 -0
- data/lib/mindee/v2/product/classification/classification.rb +20 -0
- data/lib/mindee/v2/product/classification/classification_classifier.rb +25 -0
- data/lib/mindee/v2/product/classification/classification_inference.rb +35 -0
- data/lib/mindee/v2/product/classification/classification_response.rb +32 -0
- data/lib/mindee/v2/product/classification/classification_result.rb +27 -0
- data/lib/mindee/v2/product/classification/params/classification_parameters.rb +47 -0
- data/lib/mindee/v2/product/crop/crop.rb +20 -0
- data/lib/mindee/v2/product/crop/crop_inference.rb +34 -0
- data/lib/mindee/v2/product/crop/crop_item.rb +39 -0
- data/lib/mindee/v2/product/crop/crop_response.rb +40 -0
- data/lib/mindee/v2/product/crop/crop_result.rb +34 -0
- data/lib/mindee/v2/product/crop/params/crop_parameters.rb +47 -0
- data/lib/mindee/v2/product/extraction/extraction.rb +21 -0
- data/lib/mindee/v2/product/extraction/extraction_inference.rb +40 -0
- data/lib/mindee/v2/product/extraction/extraction_response.rb +32 -0
- data/lib/mindee/v2/product/extraction/extraction_result.rb +44 -0
- data/lib/mindee/v2/product/extraction/params/data_schema.rb +51 -0
- data/lib/mindee/v2/product/extraction/params/data_schema_field.rb +69 -0
- data/lib/mindee/v2/product/extraction/params/data_schema_replace.rb +39 -0
- data/lib/mindee/v2/product/extraction/params/extraction_parameters.rb +125 -0
- data/lib/mindee/v2/product/ocr/ocr.rb +20 -0
- data/lib/mindee/v2/product/ocr/ocr_inference.rb +34 -0
- data/lib/mindee/v2/product/ocr/ocr_page.rb +33 -0
- data/lib/mindee/v2/product/ocr/ocr_response.rb +32 -0
- data/lib/mindee/v2/product/ocr/ocr_result.rb +34 -0
- data/lib/mindee/v2/product/ocr/ocr_word.rb +29 -0
- data/lib/mindee/v2/product/ocr/params/ocr_parameters.rb +47 -0
- data/lib/mindee/v2/product/split/params/split_parameters.rb +48 -0
- data/lib/mindee/v2/product/split/split.rb +19 -0
- data/lib/mindee/v2/product/split/split_inference.rb +34 -0
- data/lib/mindee/v2/product/split/split_range.rb +38 -0
- data/lib/mindee/v2/product/split/split_response.rb +40 -0
- data/lib/mindee/v2/product/split/split_result.rb +34 -0
- data/lib/mindee/v2/product.rb +7 -0
- data/lib/mindee/v2.rb +7 -0
- data/lib/mindee/version.rb +26 -0
- data/lib/mindee.rb +135 -0
- data/mindee-lite.gemspec +36 -0
- data/mindee.gemspec +44 -0
- data/sig/custom/marcel.rbs +3 -0
- data/sig/custom/mini_magick.rbs +31 -0
- data/sig/custom/net_http.rbs +43 -0
- data/sig/custom/origami.rbs +59 -0
- data/sig/mindee/dependency.rbs +13 -0
- data/sig/mindee/error/mindee_error.rbs +13 -0
- data/sig/mindee/error/mindee_http_error.rbs +17 -0
- data/sig/mindee/error/mindee_http_error_v2.rbs +15 -0
- data/sig/mindee/error/mindee_http_unknown_error_v2.rbs +9 -0
- data/sig/mindee/error/mindee_input_error.rbs +18 -0
- data/sig/mindee/geometry/min_max.rbs +11 -0
- data/sig/mindee/geometry/point.rbs +14 -0
- data/sig/mindee/geometry/polygon.rbs +12 -0
- data/sig/mindee/geometry/quadrilateral.rbs +15 -0
- data/sig/mindee/geometry/utils.rbs +13 -0
- data/sig/mindee/http/http_error_handler.rbs +15 -0
- data/sig/mindee/http/response_validation.rbs +11 -0
- data/sig/mindee/image/extracted_image.rbs +21 -0
- data/sig/mindee/image/image_compressor.rbs +8 -0
- data/sig/mindee/image/image_extractor.rbs +13 -0
- data/sig/mindee/image/image_utils.rbs +19 -0
- data/sig/mindee/input/base_parameters.rbs +35 -0
- data/sig/mindee/input/local_response.rbs +14 -0
- data/sig/mindee/input/polling_options.rbs +12 -0
- data/sig/mindee/input/sources/base64_input_source.rbs +11 -0
- data/sig/mindee/input/sources/bytes_input_source.rbs +10 -0
- data/sig/mindee/input/sources/file_input_source.rbs +10 -0
- data/sig/mindee/input/sources/local_input_source.rbs +30 -0
- data/sig/mindee/input/sources/path_input_source.rbs +10 -0
- data/sig/mindee/input/sources/url_input_source.rbs +20 -0
- data/sig/mindee/logging/logger.rbs +11 -0
- data/sig/mindee/page_options.rbs +11 -0
- data/sig/mindee/pdf/extracted_pdf.rbs +17 -0
- data/sig/mindee/pdf/pdf_compressor.rbs +15 -0
- data/sig/mindee/pdf/pdf_extractor.rbs +19 -0
- data/sig/mindee/pdf/pdf_processor.rbs +12 -0
- data/sig/mindee/pdf/pdf_tools.rbs +31 -0
- data/sig/mindee/v1/client.rbs +84 -0
- data/sig/mindee/v1/extraction/multi_receipts_extractor.rbs +8 -0
- data/sig/mindee/v1/http/endpoint.rbs +41 -0
- data/sig/mindee/v1/http/workflow_endpoint.rbs +22 -0
- data/sig/mindee/v1/parsing/common/api_request.rbs +22 -0
- data/sig/mindee/v1/parsing/common/api_response.rbs +31 -0
- data/sig/mindee/v1/parsing/common/document.rbs +32 -0
- data/sig/mindee/v1/parsing/common/execution.rbs +26 -0
- data/sig/mindee/v1/parsing/common/execution_file.rbs +16 -0
- data/sig/mindee/v1/parsing/common/execution_priority.rbs +16 -0
- data/sig/mindee/v1/parsing/common/extras/cropper_extra.rbs +18 -0
- data/sig/mindee/v1/parsing/common/extras/extras.rbs +24 -0
- data/sig/mindee/v1/parsing/common/extras/full_text_ocr_extra.rbs +22 -0
- data/sig/mindee/v1/parsing/common/extras/rag_extra.rbs +19 -0
- data/sig/mindee/v1/parsing/common/inference.rbs +31 -0
- data/sig/mindee/v1/parsing/common/job.rbs +24 -0
- data/sig/mindee/v1/parsing/common/ocr/mvision_v1.rbs +20 -0
- data/sig/mindee/v1/parsing/common/ocr/ocr.rbs +56 -0
- data/sig/mindee/v1/parsing/common/orientation.rbs +15 -0
- data/sig/mindee/v1/parsing/common/page.rbs +19 -0
- data/sig/mindee/v1/parsing/common/prediction.rbs +14 -0
- data/sig/mindee/v1/parsing/common/product.rbs +16 -0
- data/sig/mindee/v1/parsing/common/workflow_response.rbs +22 -0
- data/sig/mindee/v1/parsing/standard/abstract_field.rbs +30 -0
- data/sig/mindee/v1/parsing/standard/address_field.rbs +28 -0
- data/sig/mindee/v1/parsing/standard/amount_field.rbs +16 -0
- data/sig/mindee/v1/parsing/standard/base_field.rbs +16 -0
- data/sig/mindee/v1/parsing/standard/boolean_field.rbs +16 -0
- data/sig/mindee/v1/parsing/standard/classification_field.rbs +12 -0
- data/sig/mindee/v1/parsing/standard/company_registration_field.rbs +20 -0
- data/sig/mindee/v1/parsing/standard/date_field.rbs +20 -0
- data/sig/mindee/v1/parsing/standard/feature_field.rbs +12 -0
- data/sig/mindee/v1/parsing/standard/locale_field.rbs +24 -0
- data/sig/mindee/v1/parsing/standard/payment_details_field.rbs +19 -0
- data/sig/mindee/v1/parsing/standard/position_field.rbs +26 -0
- data/sig/mindee/v1/parsing/standard/string_field.rbs +16 -0
- data/sig/mindee/v1/parsing/standard/tax_field.rbs +33 -0
- data/sig/mindee/v1/parsing/universal/universal_list_field.rbs +21 -0
- data/sig/mindee/v1/parsing/universal/universal_object_field.rbs +38 -0
- data/sig/mindee/v1/product/barcode_reader/barcode_reader_v1.rbs +13 -0
- data/sig/mindee/v1/product/barcode_reader/barcode_reader_v1_document.rbs +16 -0
- data/sig/mindee/v1/product/barcode_reader/barcode_reader_v1_page.rbs +17 -0
- data/sig/mindee/v1/product/cropper/cropper_v1.rbs +13 -0
- data/sig/mindee/v1/product/cropper/cropper_v1_document.rbs +14 -0
- data/sig/mindee/v1/product/cropper/cropper_v1_page.rbs +19 -0
- data/sig/mindee/v1/product/financial_document/financial_document_v1.rbs +13 -0
- data/sig/mindee/v1/product/financial_document/financial_document_v1_document.rbs +49 -0
- data/sig/mindee/v1/product/financial_document/financial_document_v1_line_item.rbs +35 -0
- data/sig/mindee/v1/product/financial_document/financial_document_v1_line_items.rbs +15 -0
- data/sig/mindee/v1/product/financial_document/financial_document_v1_page.rbs +17 -0
- data/sig/mindee/v1/product/fr/bank_account_details/bank_account_details_v1.rbs +15 -0
- data/sig/mindee/v1/product/fr/bank_account_details/bank_account_details_v1_document.rbs +19 -0
- data/sig/mindee/v1/product/fr/bank_account_details/bank_account_details_v1_page.rbs +19 -0
- data/sig/mindee/v1/product/fr/bank_account_details/bank_account_details_v2.rbs +15 -0
- data/sig/mindee/v1/product/fr/bank_account_details/bank_account_details_v2_bban.rbs +25 -0
- data/sig/mindee/v1/product/fr/bank_account_details/bank_account_details_v2_document.rbs +20 -0
- data/sig/mindee/v1/product/fr/bank_account_details/bank_account_details_v2_page.rbs +19 -0
- data/sig/mindee/v1/product/fr/bank_statement/bank_statement_v2.rbs +15 -0
- data/sig/mindee/v1/product/fr/bank_statement/bank_statement_v2_document.rbs +31 -0
- data/sig/mindee/v1/product/fr/bank_statement/bank_statement_v2_page.rbs +19 -0
- data/sig/mindee/v1/product/fr/bank_statement/bank_statement_v2_transaction.rbs +27 -0
- data/sig/mindee/v1/product/fr/bank_statement/bank_statement_v2_transactions.rbs +17 -0
- data/sig/mindee/v1/product/fr/id_card/id_card_v1.rbs +15 -0
- data/sig/mindee/v1/product/fr/id_card/id_card_v1_document.rbs +26 -0
- data/sig/mindee/v1/product/fr/id_card/id_card_v1_page.rbs +20 -0
- data/sig/mindee/v1/product/fr/id_card/id_card_v2.rbs +15 -0
- data/sig/mindee/v1/product/fr/id_card/id_card_v2_document.rbs +31 -0
- data/sig/mindee/v1/product/fr/id_card/id_card_v2_page.rbs +21 -0
- data/sig/mindee/v1/product/international_id/international_id_v2.rbs +13 -0
- data/sig/mindee/v1/product/international_id/international_id_v2_document.rbs +31 -0
- data/sig/mindee/v1/product/international_id/international_id_v2_page.rbs +17 -0
- data/sig/mindee/v1/product/invoice/invoice_v4.rbs +13 -0
- data/sig/mindee/v1/product/invoice/invoice_v4_document.rbs +45 -0
- data/sig/mindee/v1/product/invoice/invoice_v4_line_item.rbs +35 -0
- data/sig/mindee/v1/product/invoice/invoice_v4_line_items.rbs +15 -0
- data/sig/mindee/v1/product/invoice/invoice_v4_page.rbs +17 -0
- data/sig/mindee/v1/product/invoice_splitter/invoice_splitter_v1.rbs +13 -0
- data/sig/mindee/v1/product/invoice_splitter/invoice_splitter_v1_document.rbs +17 -0
- data/sig/mindee/v1/product/invoice_splitter/invoice_splitter_v1_invoice_page_group.rbs +21 -0
- data/sig/mindee/v1/product/invoice_splitter/invoice_splitter_v1_invoice_page_groups.rbs +15 -0
- data/sig/mindee/v1/product/invoice_splitter/invoice_splitter_v1_page.rbs +17 -0
- data/sig/mindee/v1/product/multi_receipts_detector/multi_receipts_detector_v1.rbs +14 -0
- data/sig/mindee/v1/product/multi_receipts_detector/multi_receipts_detector_v1_document.rbs +15 -0
- data/sig/mindee/v1/product/multi_receipts_detector/multi_receipts_detector_v1_page.rbs +17 -0
- data/sig/mindee/v1/product/passport/passport_v1.rbs +13 -0
- data/sig/mindee/v1/product/passport/passport_v1_document.rbs +25 -0
- data/sig/mindee/v1/product/passport/passport_v1_page.rbs +17 -0
- data/sig/mindee/v1/product/receipt/receipt_v5.rbs +13 -0
- data/sig/mindee/v1/product/receipt/receipt_v5_document.rbs +33 -0
- data/sig/mindee/v1/product/receipt/receipt_v5_line_item.rbs +27 -0
- data/sig/mindee/v1/product/receipt/receipt_v5_line_items.rbs +15 -0
- data/sig/mindee/v1/product/receipt/receipt_v5_page.rbs +17 -0
- data/sig/mindee/v1/product/resume/resume_v1.rbs +13 -0
- data/sig/mindee/v1/product/resume/resume_v1_certificate.rbs +27 -0
- data/sig/mindee/v1/product/resume/resume_v1_certificates.rbs +17 -0
- data/sig/mindee/v1/product/resume/resume_v1_document.rbs +69 -0
- data/sig/mindee/v1/product/resume/resume_v1_education.rbs +33 -0
- data/sig/mindee/v1/product/resume/resume_v1_educations.rbs +17 -0
- data/sig/mindee/v1/product/resume/resume_v1_language.rbs +23 -0
- data/sig/mindee/v1/product/resume/resume_v1_languages.rbs +17 -0
- data/sig/mindee/v1/product/resume/resume_v1_page.rbs +19 -0
- data/sig/mindee/v1/product/resume/resume_v1_professional_experience.rbs +37 -0
- data/sig/mindee/v1/product/resume/resume_v1_professional_experiences.rbs +17 -0
- data/sig/mindee/v1/product/resume/resume_v1_social_networks_url.rbs +23 -0
- data/sig/mindee/v1/product/resume/resume_v1_social_networks_urls.rbs +17 -0
- data/sig/mindee/v1/product/universal/universal.rbs +16 -0
- data/sig/mindee/v1/product/universal/universal_document.rbs +12 -0
- data/sig/mindee/v1/product/universal/universal_page.rbs +18 -0
- data/sig/mindee/v1/product/universal/universal_prediction.rbs +30 -0
- data/sig/mindee/v2/client.rbs +29 -0
- data/sig/mindee/v2/file_operation/crop.rbs +10 -0
- data/sig/mindee/v2/file_operation/crop_files.rbs +9 -0
- data/sig/mindee/v2/file_operation/split.rbs +11 -0
- data/sig/mindee/v2/file_operation/split_files.rbs +9 -0
- data/sig/mindee/v2/http/api_v2_settings.rbs +27 -0
- data/sig/mindee/v2/http/mindee_api_v2.rbs +52 -0
- data/sig/mindee/v2/parsing/base_inference.rbs +18 -0
- data/sig/mindee/v2/parsing/base_response.rbs +11 -0
- data/sig/mindee/v2/parsing/common_response.rbs +12 -0
- data/sig/mindee/v2/parsing/error_item.rbs +13 -0
- data/sig/mindee/v2/parsing/error_response.rbs +20 -0
- data/sig/mindee/v2/parsing/field/base_field.rbs +17 -0
- data/sig/mindee/v2/parsing/field/field_confidence.rbs +30 -0
- data/sig/mindee/v2/parsing/field/field_location.rbs +16 -0
- data/sig/mindee/v2/parsing/field/inference_fields.rbs +20 -0
- data/sig/mindee/v2/parsing/field/list_field.rbs +23 -0
- data/sig/mindee/v2/parsing/field/object_field.rbs +27 -0
- data/sig/mindee/v2/parsing/field/simple_field.rbs +16 -0
- data/sig/mindee/v2/parsing/inference_active_options.rbs +26 -0
- data/sig/mindee/v2/parsing/inference_file.rbs +17 -0
- data/sig/mindee/v2/parsing/inference_job.rbs +13 -0
- data/sig/mindee/v2/parsing/inference_model.rbs +12 -0
- data/sig/mindee/v2/parsing/job.rbs +24 -0
- data/sig/mindee/v2/parsing/job_response.rbs +14 -0
- data/sig/mindee/v2/parsing/job_webhook.rbs +19 -0
- data/sig/mindee/v2/parsing/rag_metadata.rbs +13 -0
- data/sig/mindee/v2/parsing/raw_text.rbs +12 -0
- data/sig/mindee/v2/parsing/raw_text_page.rbs +11 -0
- data/sig/mindee/v2/parsing/search/pagination_metadata.rbs +20 -0
- data/sig/mindee/v2/parsing/search/search_model.rbs +19 -0
- data/sig/mindee/v2/parsing/search/search_response.rbs +17 -0
- data/sig/mindee/v2/parsing/search_models.rbs +14 -0
- data/sig/mindee/v2/product/base_product.rbs +19 -0
- data/sig/mindee/v2/product/classification/classification.rbs +10 -0
- data/sig/mindee/v2/product/classification/classification_classifier.rbs +15 -0
- data/sig/mindee/v2/product/classification/classification_inference.rbs +15 -0
- data/sig/mindee/v2/product/classification/classification_response.rbs +23 -0
- data/sig/mindee/v2/product/classification/classification_result.rbs +15 -0
- data/sig/mindee/v2/product/classification/params/classification_parameters/classification_parameters.rbs +23 -0
- data/sig/mindee/v2/product/crop/crop.rbs +10 -0
- data/sig/mindee/v2/product/crop/crop_inference.rbs +14 -0
- data/sig/mindee/v2/product/crop/crop_item.rbs +18 -0
- data/sig/mindee/v2/product/crop/crop_response.rbs +25 -0
- data/sig/mindee/v2/product/crop/crop_result.rbs +14 -0
- data/sig/mindee/v2/product/crop/params/crop_parameters/crop_parameters.rbs +23 -0
- data/sig/mindee/v2/product/extraction/extraction.rbs +15 -0
- data/sig/mindee/v2/product/extraction/extraction_inference.rbs +19 -0
- data/sig/mindee/v2/product/extraction/extraction_response.rbs +24 -0
- data/sig/mindee/v2/product/extraction/extraction_result.rbs +18 -0
- data/sig/mindee/v2/product/extraction/params/data_schema.rbs +21 -0
- data/sig/mindee/v2/product/extraction/params/data_schema_field.rbs +29 -0
- data/sig/mindee/v2/product/extraction/params/data_schema_replace.rbs +21 -0
- data/sig/mindee/v2/product/extraction/params/extraction_parameters.rbs +38 -0
- data/sig/mindee/v2/product/ocr/ocr.rbs +10 -0
- data/sig/mindee/v2/product/ocr/ocr_inference.rbs +14 -0
- data/sig/mindee/v2/product/ocr/ocr_page.rbs +15 -0
- data/sig/mindee/v2/product/ocr/ocr_response.rbs +23 -0
- data/sig/mindee/v2/product/ocr/ocr_result.rbs +14 -0
- data/sig/mindee/v2/product/ocr/ocr_word.rbs +15 -0
- data/sig/mindee/v2/product/ocr/params/ocr_parameters/ocr_parameters.rbs +24 -0
- data/sig/mindee/v2/product/split/params/split_parameters/split_parameters.rbs +23 -0
- data/sig/mindee/v2/product/split/split.rbs +10 -0
- data/sig/mindee/v2/product/split/split_inference.rbs +14 -0
- data/sig/mindee/v2/product/split/split_range.rbs +18 -0
- data/sig/mindee/v2/product/split/split_response.rbs +25 -0
- data/sig/mindee/v2/product/split/split_result.rbs +14 -0
- data/sig/mindee/version.rbs +6 -0
- data/sig/mindee.rbs +62 -0
- metadata +600 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mindee
|
|
4
|
+
# Image processing module.
|
|
5
|
+
module Image
|
|
6
|
+
# Miscellaneous image operations.
|
|
7
|
+
module ImageUtils
|
|
8
|
+
# Resizes a provided MiniMagick Image with the given width & height, if present.
|
|
9
|
+
# @param image [MiniMagick::Image] MiniMagick image handle.
|
|
10
|
+
# @param width [Integer] Width to comply with.
|
|
11
|
+
# @param height [Integer] Height to comply with.
|
|
12
|
+
def self.resize_image(image, width, height)
|
|
13
|
+
if width && height
|
|
14
|
+
image.resize "#{width}x#{height}"
|
|
15
|
+
elsif width
|
|
16
|
+
image.resize width.to_s
|
|
17
|
+
elsif height
|
|
18
|
+
image.resize "x#{height}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Compresses the quality of the provided MiniMagick image.
|
|
23
|
+
# @param image [MiniMagick::Image] MiniMagick image handle.
|
|
24
|
+
# @param quality [Integer] Quality to apply to the image. This is independent of a JPG's base quality.
|
|
25
|
+
def self.compress_image_quality(image, quality)
|
|
26
|
+
image.quality quality.to_s
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Mostly here so that IDEs don't get confused on the type (@type annotation fails sometimes.)
|
|
30
|
+
# @param [MiniMagick::Image, StringIO, File, Tempfile] image The input image
|
|
31
|
+
# @return [MiniMagick::Image]
|
|
32
|
+
def self.to_image(image)
|
|
33
|
+
if image.is_a?(MiniMagick::Image)
|
|
34
|
+
image
|
|
35
|
+
elsif image.is_a?(StringIO) || image.is_a?(IO) || image.is_a?(File) || image.is_a?(Tempfile)
|
|
36
|
+
image.rewind
|
|
37
|
+
MiniMagick::Image.read(image)
|
|
38
|
+
else
|
|
39
|
+
img_class = image.class ? image.class.to_s : 'unknown format'
|
|
40
|
+
raise Error::MindeeImageError, "Expected an I/O object or a MiniMagick::Image. '#{img_class}' given instead."
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Converts a StringIO containing an image into a MiniMagick image.
|
|
45
|
+
# @param image [MiniMagick::Image] the input image.
|
|
46
|
+
# @param format [String] Format parameter, left open for the future, but should be JPEG for current use-cases.
|
|
47
|
+
# @return [StringIO]
|
|
48
|
+
def self.image_to_stringio(image, format = 'JPEG')
|
|
49
|
+
image.format format
|
|
50
|
+
blob = image.to_blob
|
|
51
|
+
stringio = StringIO.new(blob)
|
|
52
|
+
stringio.rewind
|
|
53
|
+
|
|
54
|
+
stringio
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Computes the new dimensions for a given SKBitmap, and returns a scaled down version of it relative to the
|
|
58
|
+
# provided bounds.
|
|
59
|
+
# @param [MiniMagick::Image] original Input MiniMagick image.
|
|
60
|
+
# @param max_width [Integer] Maximum width. If not specified, the horizontal ratio will remain the same.
|
|
61
|
+
# @param max_height [Integer] Maximum height. If not specified, the vertical ratio will remain the same.
|
|
62
|
+
def self.calculate_new_dimensions(original, max_width: nil, max_height: nil)
|
|
63
|
+
raise Error::MindeeImageError, 'Provided image could not be processed for resizing.' if original.nil?
|
|
64
|
+
|
|
65
|
+
return [original.width, original.height] if max_width.nil? && max_height.nil?
|
|
66
|
+
|
|
67
|
+
width_ratio = max_width ? max_width.to_f / original.width : Float::INFINITY
|
|
68
|
+
height_ratio = max_height ? max_height.to_f / original.height : Float::INFINITY
|
|
69
|
+
|
|
70
|
+
scale_factor = [width_ratio, height_ratio].min
|
|
71
|
+
|
|
72
|
+
new_width = (original.width.to_f * scale_factor).to_i
|
|
73
|
+
new_height = (original.height.to_f * scale_factor).to_i
|
|
74
|
+
|
|
75
|
+
[new_width, new_height]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Computes the Height & Width from a page's media box. Falls back to the size of the initial image.
|
|
79
|
+
# @param image [MiniMagick::Image] The initial image that will fit into the page.
|
|
80
|
+
# @param media_box [Array<Integer>, nil]
|
|
81
|
+
# @return [Array<Integer>]
|
|
82
|
+
def self.calculate_dimensions_from_media_box(image, media_box)
|
|
83
|
+
if !media_box.nil? && media_box.any?
|
|
84
|
+
[
|
|
85
|
+
media_box[2]&.to_i || image[:width].to_i,
|
|
86
|
+
media_box[3]&.to_i || image[:height].to_i,
|
|
87
|
+
]
|
|
88
|
+
else
|
|
89
|
+
[image[:width].to_i, image[:height].to_i]
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Transforms a PDF into a MagickImage. This is currently used for single-page PDFs.
|
|
94
|
+
# @param pdf_stream [StringIO] Input stream.
|
|
95
|
+
# @param image_quality [Integer] Quality to apply to the image.
|
|
96
|
+
# @return [MiniMagick::Image]
|
|
97
|
+
def self.pdf_to_magick_image(pdf_stream, image_quality)
|
|
98
|
+
compressed_image = MiniMagick::Image.read(pdf_stream.read)
|
|
99
|
+
compressed_image.format('jpg')
|
|
100
|
+
compressed_image.quality image_quality.to_s
|
|
101
|
+
compressed_image
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Retrieves the bounding box of a polygon.
|
|
105
|
+
#
|
|
106
|
+
# @param [Array<Point>, Mindee::Geometry::Polygon] polygon
|
|
107
|
+
def self.normalize_polygon(polygon)
|
|
108
|
+
if polygon.is_a?(Mindee::Geometry::Polygon) ||
|
|
109
|
+
(polygon.is_a?(Array) && polygon[0].is_a?(Mindee::Geometry::Point))
|
|
110
|
+
Mindee::Geometry.get_bounding_box(polygon)
|
|
111
|
+
elsif polygon.is_a?(Mindee::Geometry::Quadrilateral)
|
|
112
|
+
polygon
|
|
113
|
+
else
|
|
114
|
+
raise Error::MindeeGeometryError, 'Provided polygon has an invalid type.'
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Loads a buffer into a MiniMagick Image.
|
|
119
|
+
#
|
|
120
|
+
# @param [StringIO] pdf_stream Buffer containg the PDF
|
|
121
|
+
# @return [MiniMagick::Image] a valid MiniMagick image handle.
|
|
122
|
+
def self.read_page_content(pdf_stream)
|
|
123
|
+
pdf_stream.rewind
|
|
124
|
+
MiniMagick::Image.read(pdf_stream)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Crops a MiniMagick Image from a the given bounding box.
|
|
128
|
+
#
|
|
129
|
+
# @param [MiniMagick::Image] image Input Image.
|
|
130
|
+
# @param [Mindee::Geometry::MinMax] min_max_x minimum & maximum values for the x coordinates.
|
|
131
|
+
# @param [Mindee::Geometry::MinMax] min_max_y minimum & maximum values for the y coordinates.
|
|
132
|
+
def self.crop_image(image, min_max_x, min_max_y)
|
|
133
|
+
width = image[:width].to_i
|
|
134
|
+
height = image[:height].to_i
|
|
135
|
+
|
|
136
|
+
image.format('jpg')
|
|
137
|
+
new_width = (min_max_x.max - min_max_x.min) * width
|
|
138
|
+
new_height = (min_max_y.max - min_max_y.min) * height
|
|
139
|
+
image.crop("#{new_width}x#{new_height}+#{min_max_x.min * width}+#{min_max_y.min * height}")
|
|
140
|
+
|
|
141
|
+
image
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Writes a MiniMagick::Image to a buffer.
|
|
145
|
+
#
|
|
146
|
+
# @param [MiniMagick::Image] image a valid MiniMagick image.
|
|
147
|
+
# @param [StringIO] buffer
|
|
148
|
+
def self.write_image_to_buffer(image, buffer)
|
|
149
|
+
image.write(buffer)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Retrieves the file extension from the main file to apply it to the extracted images. Note: coerces pdf as jpg.
|
|
153
|
+
#
|
|
154
|
+
# @param [Mindee::Input::Source::LocalInputSource] input_source Local input source.
|
|
155
|
+
# @return [String, nil] A valid file extension.
|
|
156
|
+
def self.determine_file_extension(input_source)
|
|
157
|
+
if input_source.pdf? || input_source.filename.downcase.end_with?('pdf')
|
|
158
|
+
'jpg'
|
|
159
|
+
else
|
|
160
|
+
File.extname(input_source.filename.to_s).strip.downcase[1..].to_s
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
data/lib/mindee/image.rb
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mindee
|
|
4
|
+
module Input
|
|
5
|
+
# Base class for parameters accepted by all V2 endpoints.
|
|
6
|
+
class BaseParameters
|
|
7
|
+
# @return [String] ID of the model (required).
|
|
8
|
+
attr_reader :model_id
|
|
9
|
+
|
|
10
|
+
# @return [String, nil] Optional alias for the file.
|
|
11
|
+
attr_reader :file_alias
|
|
12
|
+
|
|
13
|
+
# @return [Array<String>, nil] Optional list of Webhooks IDs to propagate the API response to.
|
|
14
|
+
attr_reader :webhook_ids
|
|
15
|
+
|
|
16
|
+
# @return [PollingOptions] Options for polling. Set only if having timeout issues.
|
|
17
|
+
attr_reader :polling_options
|
|
18
|
+
|
|
19
|
+
# @return [Boolean, nil] Whether to close the file after parsing.
|
|
20
|
+
attr_reader :close_file
|
|
21
|
+
|
|
22
|
+
# @param [String] model_id ID of the model
|
|
23
|
+
# @param [String, nil] file_alias File alias, if applicable.
|
|
24
|
+
# @param [Array<String>, nil] webhook_ids List of webhook IDs to propagate the API response to.
|
|
25
|
+
# @param [Hash, nil] polling_options Options for polling. Set only if having timeout issues.
|
|
26
|
+
# @param [Boolean, nil] close_file Whether to close the file after parsing.
|
|
27
|
+
def initialize(
|
|
28
|
+
model_id,
|
|
29
|
+
file_alias: nil,
|
|
30
|
+
webhook_ids: nil,
|
|
31
|
+
polling_options: nil,
|
|
32
|
+
close_file: true
|
|
33
|
+
)
|
|
34
|
+
raise Error::MindeeInputError, 'Model ID is required.' if model_id.empty? || model_id.nil?
|
|
35
|
+
|
|
36
|
+
@model_id = model_id
|
|
37
|
+
@file_alias = file_alias
|
|
38
|
+
@webhook_ids = webhook_ids || []
|
|
39
|
+
@polling_options = get_clean_polling_options(polling_options)
|
|
40
|
+
@close_file = close_file.nil? || close_file
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# @return [String] Slug for the endpoint.
|
|
44
|
+
def self.slug
|
|
45
|
+
if self == BaseParameters
|
|
46
|
+
raise NotImplementedError, 'Cannot access `slug` directly on the BaseParameters class.'
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
''
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# @return [String] Slug for the endpoint.
|
|
53
|
+
def slug
|
|
54
|
+
self.class.slug
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Load from a hash
|
|
58
|
+
# @param [Hash] params Parameters to provide as a hash.
|
|
59
|
+
# @return [BaseParameters]
|
|
60
|
+
def self.from_hash(params: {})
|
|
61
|
+
load_from_hash(params: params)
|
|
62
|
+
new(
|
|
63
|
+
params[:model_id],
|
|
64
|
+
file_alias: params[:file_alias],
|
|
65
|
+
webhook_ids: params[:webhook_ids],
|
|
66
|
+
polling_options: params[:polling_options],
|
|
67
|
+
close_file: params[:close_file]
|
|
68
|
+
)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Loads a prediction from a Hash.
|
|
72
|
+
# @param [Hash] params Parameters to provide as a hash.
|
|
73
|
+
# @return [Hash]
|
|
74
|
+
def self.load_from_hash(params: {})
|
|
75
|
+
params.transform_keys!(&:to_sym)
|
|
76
|
+
|
|
77
|
+
if params.empty? || params[:model_id].nil? || params[:model_id].empty?
|
|
78
|
+
raise Error::MindeeInputError, 'Model ID is required.'
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
polling_options_input = params.fetch(:page_options, PollingOptions.new)
|
|
82
|
+
if polling_options_input.is_a?(Hash)
|
|
83
|
+
polling_options_input = polling_options_input.transform_keys(&:to_sym)
|
|
84
|
+
PollingOptions.new(
|
|
85
|
+
initial_delay_sec: polling_options_input.fetch(:initial_delay_sec, 2.0),
|
|
86
|
+
delay_sec: polling_options_input.fetch(:delay_sec, 1.5),
|
|
87
|
+
max_retries: polling_options_input.fetch(:max_retries, 80)
|
|
88
|
+
)
|
|
89
|
+
end
|
|
90
|
+
params
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Appends base form data to the provided array.
|
|
94
|
+
# @param [Array] form_data Array of form fields
|
|
95
|
+
# @return [Array]
|
|
96
|
+
def append_form_data(form_data)
|
|
97
|
+
form_data.push(['file_alias', @file_alias]) if @file_alias
|
|
98
|
+
webhook_ids = @webhook_ids || []
|
|
99
|
+
form_data.push(['webhook_ids', webhook_ids.join(',')]) unless @webhook_ids.nil? || webhook_ids.empty?
|
|
100
|
+
form_data
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Validates the parameters for async auto-polling
|
|
104
|
+
def validate_async_params
|
|
105
|
+
min_delay_sec = 1
|
|
106
|
+
min_initial_delay_sec = 1
|
|
107
|
+
min_retries = 2
|
|
108
|
+
|
|
109
|
+
if @polling_options.delay_sec < min_delay_sec
|
|
110
|
+
raise ArgumentError,
|
|
111
|
+
"Cannot set auto-poll delay to less than #{min_delay_sec} second(s)"
|
|
112
|
+
end
|
|
113
|
+
if @polling_options.initial_delay_sec < min_initial_delay_sec
|
|
114
|
+
raise ArgumentError,
|
|
115
|
+
"Cannot set initial parsing delay to less than #{min_initial_delay_sec} second(s)"
|
|
116
|
+
end
|
|
117
|
+
return unless @polling_options.max_retries < min_retries
|
|
118
|
+
|
|
119
|
+
raise ArgumentError,
|
|
120
|
+
"Cannot set auto-poll retries to less than #{min_retries}"
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
private
|
|
124
|
+
|
|
125
|
+
# Cleans a proper polling options object potentially from a hash.
|
|
126
|
+
# @param [Hash, PollingOptions, nil] polling_options Polling options.
|
|
127
|
+
# @return [PollingOptions] Valid polling options object.
|
|
128
|
+
def get_clean_polling_options(polling_options)
|
|
129
|
+
return PollingOptions.new if polling_options.is_a?(PollingOptions)
|
|
130
|
+
|
|
131
|
+
if polling_options.is_a?(Hash)
|
|
132
|
+
polling_options = polling_options.transform_keys(&:to_sym)
|
|
133
|
+
output_polling_options = PollingOptions.new(
|
|
134
|
+
initial_delay_sec: polling_options.fetch(:initial_delay_sec, 2.0),
|
|
135
|
+
delay_sec: polling_options.fetch(:delay_sec, 1.5),
|
|
136
|
+
max_retries: polling_options.fetch(:max_retries, 80)
|
|
137
|
+
)
|
|
138
|
+
else
|
|
139
|
+
output_polling_options = if polling_options.is_a?(PollingOptions)
|
|
140
|
+
polling_options || PollingOptions.new
|
|
141
|
+
else
|
|
142
|
+
PollingOptions.new
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
output_polling_options
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'openssl'
|
|
5
|
+
require 'stringio'
|
|
6
|
+
require 'pathname'
|
|
7
|
+
require 'tempfile'
|
|
8
|
+
|
|
9
|
+
module Mindee
|
|
10
|
+
module Input
|
|
11
|
+
# Response loaded locally.
|
|
12
|
+
class LocalResponse
|
|
13
|
+
attr_reader :file
|
|
14
|
+
|
|
15
|
+
# @param input_file [File, Tempfile, IO, StringIO, String, Pathname] The input file, which can be a StringIO.
|
|
16
|
+
def initialize(input_file)
|
|
17
|
+
case input_file
|
|
18
|
+
when IO, StringIO, File, Tempfile
|
|
19
|
+
str_stripped = input_file.read.to_s.gsub(%r{[\r\n]}, '')
|
|
20
|
+
@file = StringIO.new(str_stripped)
|
|
21
|
+
@file.rewind
|
|
22
|
+
when Pathname, String
|
|
23
|
+
@file = if Pathname(input_file.to_s).exist?
|
|
24
|
+
StringIO.new(File.read(input_file.to_s, encoding: 'utf-8').gsub(%r{[\r\n]}, ''))
|
|
25
|
+
else
|
|
26
|
+
StringIO.new(input_file.to_s.gsub(%r{[\r\n]}, ''))
|
|
27
|
+
end
|
|
28
|
+
@file.rewind
|
|
29
|
+
else
|
|
30
|
+
raise Error::MindeeInputError, "Incompatible type for input '#{input_file.class}'."
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Returns the file as a hash.
|
|
35
|
+
# @return [Hash]
|
|
36
|
+
def as_hash
|
|
37
|
+
@file.rewind
|
|
38
|
+
file_str = @file.read or raise 'File could not be read'
|
|
39
|
+
JSON.parse(file_str, object_class: Hash)
|
|
40
|
+
rescue JSON::ParserError
|
|
41
|
+
raise Error::MindeeInputError, "File is not a valid dict. #{file_str}"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Processes the secret key
|
|
45
|
+
# @param secret_key [String] the secret key as plain text.
|
|
46
|
+
# @return [String]
|
|
47
|
+
def self.process_secret_key(secret_key)
|
|
48
|
+
secret_key.is_a?(String) ? secret_key.encode('utf-8') : secret_key
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# @param [String] secret_key [String] Secret key, either a string or a byte/byte array.
|
|
52
|
+
# @return [String]
|
|
53
|
+
def get_hmac_signature(secret_key)
|
|
54
|
+
algorithm = OpenSSL::Digest.new('sha256')
|
|
55
|
+
begin
|
|
56
|
+
@file.rewind
|
|
57
|
+
mac = OpenSSL::HMAC.hexdigest(algorithm, self.class.process_secret_key(secret_key),
|
|
58
|
+
@file.read || raise('File could not be read'))
|
|
59
|
+
rescue StandardError
|
|
60
|
+
raise Error::MindeeInputError, 'Could not get HMAC signature from payload.'
|
|
61
|
+
end
|
|
62
|
+
mac
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# @param secret_key [String] Secret key, either a string or a byte/byte array.
|
|
66
|
+
# @param signature [String] Signature to match
|
|
67
|
+
# @return [bool]
|
|
68
|
+
def valid_hmac_signature?(secret_key, signature)
|
|
69
|
+
signature == get_hmac_signature(secret_key)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Deserializes a loaded response
|
|
73
|
+
# @param response_class [Class<V2::Parsing::BaseResponse>] class to return.
|
|
74
|
+
# @return [V2::Parsing::JobResponse, Mindee::V2::Parsing::BaseResponse]
|
|
75
|
+
def deserialize_response(response_class)
|
|
76
|
+
response_class.new(as_hash) # : Mindee::V2::Parsing::JobResponse | Mindee::V2::Parsing::BaseResponse
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mindee
|
|
4
|
+
module Input
|
|
5
|
+
# Options for asynchronous polling.
|
|
6
|
+
class PollingOptions
|
|
7
|
+
# @return [Integer, Float] Initial delay before the first polling attempt (in seconds).
|
|
8
|
+
attr_reader :initial_delay_sec
|
|
9
|
+
|
|
10
|
+
# @return [Integer, Float] Delay between each polling attempt (in seconds).
|
|
11
|
+
attr_reader :delay_sec
|
|
12
|
+
|
|
13
|
+
# @return [Integer] Total number of polling attempts.
|
|
14
|
+
attr_reader :max_retries
|
|
15
|
+
|
|
16
|
+
# @param initial_delay_sec [Float] Initial delay before the first attempt (default:2.0).
|
|
17
|
+
# @param delay_sec [Float] Delay between attempts (default: 1.5).
|
|
18
|
+
# @param max_retries [Integer] Maximum number of retries (default:80).
|
|
19
|
+
def initialize(initial_delay_sec: 2.0, delay_sec: 1.5, max_retries: 80)
|
|
20
|
+
@initial_delay_sec = initial_delay_sec
|
|
21
|
+
@delay_sec = delay_sec
|
|
22
|
+
@max_retries = max_retries
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'stringio'
|
|
4
|
+
|
|
5
|
+
module Mindee
|
|
6
|
+
module Input
|
|
7
|
+
module Source
|
|
8
|
+
# Load a document from a base64 string.
|
|
9
|
+
class Base64InputSource < LocalInputSource
|
|
10
|
+
# @param base64_string [String]
|
|
11
|
+
# @param filename [String]
|
|
12
|
+
# @param repair_pdf [bool]
|
|
13
|
+
def initialize(base64_string, filename, repair_pdf: false)
|
|
14
|
+
io_stream = StringIO.new(base64_string.unpack1('m*').to_s)
|
|
15
|
+
io_stream.set_encoding Encoding::BINARY
|
|
16
|
+
super(io_stream, filename, repair_pdf: repair_pdf)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Overload of the same function to prevent a base64 from being re-encoded.
|
|
20
|
+
# @param close [bool]
|
|
21
|
+
# @return [Array<[String, aBinaryString ], [Hash, nil] >]
|
|
22
|
+
def read_contents(close: true)
|
|
23
|
+
@io_stream.seek(0)
|
|
24
|
+
data = @io_stream.read
|
|
25
|
+
@io_stream.close if close
|
|
26
|
+
[[data].pack('m'), { filename: Source.convert_to_unicode_escape(@filename) }]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'stringio'
|
|
4
|
+
|
|
5
|
+
module Mindee
|
|
6
|
+
module Input
|
|
7
|
+
module Source
|
|
8
|
+
# Load a document from raw bytes.
|
|
9
|
+
class BytesInputSource < LocalInputSource
|
|
10
|
+
# @param raw_bytes [String]
|
|
11
|
+
# @param filename [String]
|
|
12
|
+
# @param repair_pdf [bool]
|
|
13
|
+
def initialize(raw_bytes, filename, repair_pdf: false)
|
|
14
|
+
io_stream = StringIO.new(raw_bytes)
|
|
15
|
+
io_stream.set_encoding Encoding::BINARY
|
|
16
|
+
super(io_stream, filename, repair_pdf: repair_pdf)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'stringio'
|
|
4
|
+
|
|
5
|
+
module Mindee
|
|
6
|
+
module Input
|
|
7
|
+
module Source
|
|
8
|
+
# Load a document from a file handle.
|
|
9
|
+
class FileInputSource < LocalInputSource
|
|
10
|
+
# @param input_file [File]
|
|
11
|
+
# @param filename [String]
|
|
12
|
+
# @param repair_pdf [bool]
|
|
13
|
+
def initialize(input_file, filename, repair_pdf: false)
|
|
14
|
+
io_stream = input_file
|
|
15
|
+
super(io_stream, filename, repair_pdf: repair_pdf)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|