diff --git a/bin/cli_products.rb b/bin/cli_products.rb index d2ab28715..41df18367 100644 --- a/bin/cli_products.rb +++ b/bin/cli_products.rb @@ -163,10 +163,4 @@ sync: false, async: true, }, - "us-w9" => { - description: "W9", - doc_class: Mindee::Product::US::W9::W9V1, - sync: true, - async: false, - }, } diff --git a/docs/code_samples/us_w9_v1.txt b/docs/code_samples/us_w9_v1.txt deleted file mode 100644 index 9eb9fdf44..000000000 --- a/docs/code_samples/us_w9_v1.txt +++ /dev/null @@ -1,21 +0,0 @@ -# -# Install the Ruby client library by running: -# gem install mindee -# - -require 'mindee' - -# Init a new client -mindee_client = Mindee::Client.new(api_key: 'my-api-key') - -# Load a file from disk -input_source = mindee_client.source_from_path('/path/to/the/file.ext') - -# Parse the file -result = mindee_client.parse( - input_source, - Mindee::Product::US::W9::W9V1 -) - -# Print a full summary of the parsed data in RST format -puts result.document diff --git a/docs/global_products/expense_receipts_v5.md b/docs/global_products/expense_receipts_v5.md index 1cbd74b1b..13fc5f328 100644 --- a/docs/global_products/expense_receipts_v5.md +++ b/docs/global_products/expense_receipts_v5.md @@ -227,6 +227,7 @@ Aside from the basic `Field` attributes, the tax field `TaxField` also implement * **rate** (`Float`): the tax rate applied to an item can be expressed as a percentage. Can be `nil`. * **code** (`String`): tax code (or equivalent, depending on the origin of the document). Can be `nil`. * **base** (`Float`): base amount used for the tax. Can be `nil`. +* **value** (`Float`): the value of the tax. Can be `nil`. > Note: currently `TaxField` is not used on its own, and is accessed through a parent `Taxes` object, an array-like structure. diff --git a/docs/global_products/financial_document_v1.md b/docs/global_products/financial_document_v1.md index 29fbe0410..41a41855a 100644 --- a/docs/global_products/financial_document_v1.md +++ b/docs/global_products/financial_document_v1.md @@ -272,6 +272,7 @@ Aside from the basic `Field` attributes, the tax field `TaxField` also implement * **rate** (`Float`): the tax rate applied to an item can be expressed as a percentage. Can be `nil`. * **code** (`String`): tax code (or equivalent, depending on the origin of the document). Can be `nil`. * **base** (`Float`): base amount used for the tax. Can be `nil`. +* **value** (`Float`): the value of the tax. Can be `nil`. > Note: currently `TaxField` is not used on its own, and is accessed through a parent `Taxes` object, an array-like structure. diff --git a/docs/global_products/invoices_v4.md b/docs/global_products/invoices_v4.md index f095091f7..f23346a3e 100644 --- a/docs/global_products/invoices_v4.md +++ b/docs/global_products/invoices_v4.md @@ -260,6 +260,7 @@ Aside from the basic `Field` attributes, the tax field `TaxField` also implement * **rate** (`Float`): the tax rate applied to an item can be expressed as a percentage. Can be `nil`. * **code** (`String`): tax code (or equivalent, depending on the origin of the document). Can be `nil`. * **base** (`Float`): base amount used for the tax. Can be `nil`. +* **value** (`Float`): the value of the tax. Can be `nil`. > Note: currently `TaxField` is not used on its own, and is accessed through a parent `Taxes` object, an array-like structure. diff --git a/docs/localized_products/us_w9_v1.md b/docs/localized_products/us_w9_v1.md deleted file mode 100644 index e3d12a626..000000000 --- a/docs/localized_products/us_w9_v1.md +++ /dev/null @@ -1,230 +0,0 @@ ---- -title: US W9 -category: 622b805aaec68102ea7fcbc2 -slug: ruby-us-w9-ocr -parentDoc: 67b49e29a2cd6f08d69a40d8 ---- -The Ruby Client Library supports the [W9 API](https://platform.mindee.com/mindee/us_w9). - - -> πŸ“ Product Specs -> -> | Specification | Details | -> | ------------------------------ | -------------------------------------------------- | -> | Endpoint Name | `us_w9` | -> | Recommended Version | `v1.0` | -> | Supports Polling/Webhooks | ❌ No | -> | Support Synchronous HTTP Calls | βœ”οΈ Yes | -> | Geography | πŸ‡ΊπŸ‡Έ United States | - - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/us_w9/default_sample.jpg), -we are going to illustrate how to extract the data that we want using the Ruby Client Library. -![W9 sample](https://github.com/mindee/client-lib-test-data/blob/main/products/us_w9/default_sample.jpg?raw=true) - -# Quick-Start -```rb -# -# Install the Ruby client library by running: -# gem install mindee -# - -require 'mindee' - -# Init a new client -mindee_client = Mindee::Client.new(api_key: 'my-api-key') - -# Load a file from disk -input_source = mindee_client.source_from_path('/path/to/the/file.ext') - -# Parse the file -result = mindee_client.parse( - input_source, - Mindee::Product::US::W9::W9V1 -) - -# Print a full summary of the parsed data in RST format -puts result.document -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: d7c5b25f-e0d3-4491-af54-6183afa1aaab -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/us_w9 v1.0 -:Rotation applied: Yes - -Prediction -========== - -Page Predictions -================ - -Page 0 ------- -:Name: Stephen W Hawking -:SSN: 560758145 -:Address: Somewhere In Milky Way -:City State Zip: Probably Still At Cambridge P O Box CB1 -:Business Name: -:EIN: 942203664 -:Tax Classification: individual -:Tax Classification Other Details: -:W9 Revision Date: august 2013 -:Signature Position: Polygon with 4 points. -:Signature Date Position: -:Tax Classification LLC: -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. -* **confidence** (Float, nil): the confidence score of the field prediction. -* **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). - - -Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string. - - -### Position Field -The position field `PositionField` does not implement all the basic `Field` attributes, only **bounding_box**, -**polygon** and **page_id**. On top of these, it has access to: - -* **rectangle** (`Mindee::Geometry::Quadrilateral`): a Polygon with four points that may be oriented (even beyond -canvas). -* **quadrangle** (`Mindee::Geometry::Quadrilateral`): a free polygon made up of four points. - -### String Field -The text field `StringField` only has one constraint: it's **value** is a `String` (or `nil`). - -## Page-Level Fields -Some fields are constrained to the page level, and so will not be retrievable at document level. - -# Attributes -The following fields are extracted for W9 V1: - -## Address -[πŸ“„](#page-level-fields "This field is only present on individual pages.")**address** ([StringField](#string-field)): The street address (number, street, and apt. or suite no.) of the applicant. - -```rb - result.document.address.each do |address_elem| - puts address_elem.value - end -``` - -## Business Name -[πŸ“„](#page-level-fields "This field is only present on individual pages.")**business_name** ([StringField](#string-field)): The business name or disregarded entity name, if different from Name. - -```rb - result.document.business_name.each do |business_name_elem| - puts business_name_elem.value - end -``` - -## City State Zip -[πŸ“„](#page-level-fields "This field is only present on individual pages.")**city_state_zip** ([StringField](#string-field)): The city, state, and ZIP code of the applicant. - -```rb - result.document.city_state_zip.each do |city_state_zip_elem| - puts city_state_zip_elem.value - end -``` - -## EIN -[πŸ“„](#page-level-fields "This field is only present on individual pages.")**ein** ([StringField](#string-field)): The employer identification number. - -```rb - result.document.ein.each do |ein_elem| - puts ein_elem.value - end -``` - -## Name -[πŸ“„](#page-level-fields "This field is only present on individual pages.")**name** ([StringField](#string-field)): Name as shown on the applicant's income tax return. - -```rb - result.document.name.each do |name_elem| - puts name_elem.value - end -``` - -## Signature Date Position -[πŸ“„](#page-level-fields "This field is only present on individual pages.")**signature_date_position** ([PositionField](#position-field)): Position of the signature date on the document. - -```rb - result.document.signature_date_position.each do |signature_date_position_elem| - puts signature_date_position_elem.polygon - end -``` - -## Signature Position -[πŸ“„](#page-level-fields "This field is only present on individual pages.")**signature_position** ([PositionField](#position-field)): Position of the signature on the document. - -```rb - result.document.signature_position.each do |signature_position_elem| - puts signature_position_elem.polygon - end -``` - -## SSN -[πŸ“„](#page-level-fields "This field is only present on individual pages.")**ssn** ([StringField](#string-field)): The applicant's social security number. - -```rb - result.document.ssn.each do |ssn_elem| - puts ssn_elem.value - end -``` - -## Tax Classification -[πŸ“„](#page-level-fields "This field is only present on individual pages.")**tax_classification** ([StringField](#string-field)): The federal tax classification, which can vary depending on the revision date. - -```rb - result.document.tax_classification.each do |tax_classification_elem| - puts tax_classification_elem.value - end -``` - -## Tax Classification LLC -[πŸ“„](#page-level-fields "This field is only present on individual pages.")**tax_classification_llc** ([StringField](#string-field)): Depending on revision year, among S, C, P or D for Limited Liability Company Classification. - -```rb - result.document.tax_classification_llc.each do |tax_classification_llc_elem| - puts tax_classification_llc_elem.value - end -``` - -## Tax Classification Other Details -[πŸ“„](#page-level-fields "This field is only present on individual pages.")**tax_classification_other_details** ([StringField](#string-field)): Tax Classification Other Details. - -```rb - result.document.tax_classification_other_details.each do |tax_classification_other_details_elem| - puts tax_classification_other_details_elem.value - end -``` - -## W9 Revision Date -[πŸ“„](#page-level-fields "This field is only present on individual pages.")**w9_revision_date** ([StringField](#string-field)): The Revision month and year of the W9 form. - -```rb - result.document.w9_revision_date.each do |w9_revision_date_elem| - puts w9_revision_date_elem.value - end -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/lib/mindee/product.rb b/lib/mindee/product.rb index 8bc04026d..24f114626 100644 --- a/lib/mindee/product.rb +++ b/lib/mindee/product.rb @@ -31,4 +31,3 @@ require_relative 'product/us/healthcare_card/healthcare_card_v1' require_relative 'product/us/us_mail/us_mail_v2' require_relative 'product/us/us_mail/us_mail_v3' -require_relative 'product/us/w9/w9_v1' diff --git a/lib/mindee/product/us/w9/w9_v1.rb b/lib/mindee/product/us/w9/w9_v1.rb deleted file mode 100644 index dcafdaa0b..000000000 --- a/lib/mindee/product/us/w9/w9_v1.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' -require_relative 'w9_v1_document' -require_relative 'w9_v1_page' - -module Mindee - module Product - module US - # W9 module. - module W9 - # W9 API version 1 inference prediction. - class W9V1 < Mindee::Parsing::Common::Inference - @endpoint_name = 'us_w9' - @endpoint_version = '1' - @has_async = false - @has_sync = true - - # @param prediction [Hash] - def initialize(prediction) - super - @prediction = W9V1Document.new(prediction['prediction'], nil) - @pages = [] - prediction['pages'].each do |page| - @pages.push(W9V1Page.new(page)) - end - end - - class << self - # Name of the endpoint for this product. - # @return [String] - attr_reader :endpoint_name - # Version for this product. - # @return [String] - attr_reader :endpoint_version - # Whether this product has access to an asynchronous endpoint. - # @return [bool] - attr_reader :has_async - # Whether this product has access to synchronous endpoint. - # @return [bool] - attr_reader :has_sync - end - end - end - end - end -end diff --git a/lib/mindee/product/us/w9/w9_v1_document.rb b/lib/mindee/product/us/w9/w9_v1_document.rb deleted file mode 100644 index 89368dfa2..000000000 --- a/lib/mindee/product/us/w9/w9_v1_document.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' - -module Mindee - module Product - module US - module W9 - # W9 API version 1.0 document data. - class W9V1Document < Mindee::Parsing::Common::Prediction - end - end - end - end -end diff --git a/lib/mindee/product/us/w9/w9_v1_page.rb b/lib/mindee/product/us/w9/w9_v1_page.rb deleted file mode 100644 index e2c17d8fc..000000000 --- a/lib/mindee/product/us/w9/w9_v1_page.rb +++ /dev/null @@ -1,133 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' -require_relative 'w9_v1_document' - -module Mindee - module Product - module US - module W9 - # W9 API version 1.0 page data. - class W9V1Page < Mindee::Parsing::Common::Page - # @param prediction [Hash] - def initialize(prediction) - super - @prediction = if prediction['prediction'].empty? - nil - else - W9V1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) - end - end - end - - # W9 V1 page prediction. - class W9V1PagePrediction < W9V1Document - include Mindee::Parsing::Standard - - # The street address (number, street, and apt. or suite no.) of the applicant. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :address - # The business name or disregarded entity name, if different from Name. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :business_name - # The city, state, and ZIP code of the applicant. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :city_state_zip - # The employer identification number. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :ein - # Name as shown on the applicant's income tax return. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :name - # Position of the signature date on the document. - # @return [Mindee::Parsing::Standard::PositionField] - attr_reader :signature_date_position - # Position of the signature on the document. - # @return [Mindee::Parsing::Standard::PositionField] - attr_reader :signature_position - # The applicant's social security number. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :ssn - # The federal tax classification, which can vary depending on the revision date. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :tax_classification - # Depending on revision year, among S, C, P or D for Limited Liability Company Classification. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :tax_classification_llc - # Tax Classification Other Details. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :tax_classification_other_details - # The Revision month and year of the W9 form. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :w9_revision_date - - # @param prediction [Hash] - # @param page_id [Integer, nil] - def initialize(prediction, page_id) - @address = Parsing::Standard::StringField.new( - prediction['address'], - page_id - ) - @business_name = Parsing::Standard::StringField.new( - prediction['business_name'], - page_id - ) - @city_state_zip = Parsing::Standard::StringField.new( - prediction['city_state_zip'], - page_id - ) - @ein = Parsing::Standard::StringField.new(prediction['ein'], page_id) - @name = Parsing::Standard::StringField.new(prediction['name'], page_id) - @signature_date_position = Parsing::Standard::PositionField.new( - prediction['signature_date_position'], - page_id - ) - @signature_position = Parsing::Standard::PositionField.new( - prediction['signature_position'], - page_id - ) - @ssn = Parsing::Standard::StringField.new(prediction['ssn'], page_id) - @tax_classification = Parsing::Standard::StringField.new( - prediction['tax_classification'], - page_id - ) - @tax_classification_llc = Parsing::Standard::StringField.new( - prediction['tax_classification_llc'], - page_id - ) - @tax_classification_other_details = Parsing::Standard::StringField.new( - prediction['tax_classification_other_details'], - page_id - ) - @w9_revision_date = Parsing::Standard::StringField.new( - prediction['w9_revision_date'], - page_id - ) - super - end - - # @return [String] - def to_s - out_str = String.new - out_str << "\n:Name: #{@name}".rstrip - out_str << "\n:SSN: #{@ssn}".rstrip - out_str << "\n:Address: #{@address}".rstrip - out_str << "\n:City State Zip: #{@city_state_zip}".rstrip - out_str << "\n:Business Name: #{@business_name}".rstrip - out_str << "\n:EIN: #{@ein}".rstrip - out_str << "\n:Tax Classification: #{@tax_classification}".rstrip - out_str << "\n:Tax Classification Other Details: #{@tax_classification_other_details}".rstrip - out_str << "\n:W9 Revision Date: #{@w9_revision_date}".rstrip - out_str << "\n:Signature Position: #{@signature_position}".rstrip - out_str << "\n:Signature Date Position: #{@signature_date_position}".rstrip - out_str << "\n:Tax Classification LLC: #{@tax_classification_llc}".rstrip - out_str - end - end - end - end - end -end diff --git a/spec/product/us/w9_v1_spec.rb b/spec/product/us/w9_v1_spec.rb deleted file mode 100644 index 77ec5cd98..000000000 --- a/spec/product/us/w9_v1_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true - -require 'json' -require 'mindee/product' -require 'mindee/parsing' - -require_relative '../../data' - -DIR_US_W9_V1 = File.join(DATA_DIR, 'products', 'us_w9', 'response_v1').freeze - -describe Mindee::Product::US::W9::W9V1 do - context 'A W9 V1' do - it 'should load an empty document prediction' do - response = load_json(DIR_US_W9_V1, 'empty.json') - inference = Mindee::Parsing::Common::Document.new( - Mindee::Product::US::W9::W9V1, - response['document'] - ).inference - expect(inference.product.type).to eq('standard') - end - - it 'should load a complete document prediction' do - to_string = read_file(DIR_US_W9_V1, 'summary_full.rst') - response = load_json(DIR_US_W9_V1, 'complete.json') - document = Mindee::Parsing::Common::Document.new( - Mindee::Product::US::W9::W9V1, - response['document'] - ) - expect(document.to_s).to eq(to_string) - end - it 'should load a complete page 0 prediction' do - to_string = read_file(DIR_US_W9_V1, 'summary_page0.rst') - response = load_json(DIR_US_W9_V1, 'complete.json') - document = Mindee::Parsing::Common::Document.new( - Mindee::Product::US::W9::W9V1, - response['document'] - ) - page = document.inference.pages[0] - expect(page.to_s).to eq(to_string) - end - end -end