mindee 3.9.0 → 3.11.0
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 +4 -4
- data/CHANGELOG.md +14 -0
- data/docs/code_samples/us_mail_v2_async.txt +19 -0
- data/docs/us_mail_v2.md +135 -0
- data/lib/mindee/client.rb +11 -0
- data/lib/mindee/extraction/ocr_extractor.rb +110 -0
- data/lib/mindee/extraction/tax_extractor.rb +322 -0
- data/lib/mindee/extraction.rb +3 -0
- data/lib/mindee/geometry/utils.rb +19 -0
- data/lib/mindee/input/local_response.rb +72 -0
- data/lib/mindee/input/sources.rb +3 -3
- data/lib/mindee/parsing/common/api_response.rb +5 -4
- data/lib/mindee/parsing/common/ocr/mvision_v1.rb +16 -0
- data/lib/mindee/parsing/common/ocr/ocr.rb +10 -0
- data/lib/mindee/parsing/standard/base_field.rb +3 -1
- data/lib/mindee/parsing/standard/boolean_field.rb +20 -0
- data/lib/mindee/parsing/standard/locale_field.rb +4 -4
- data/lib/mindee/parsing/standard.rb +1 -0
- data/lib/mindee/product/us/us_mail/us_mail_v2.rb +41 -0
- data/lib/mindee/product/us/us_mail/us_mail_v2_document.rb +100 -0
- data/lib/mindee/product/us/us_mail/us_mail_v2_page.rb +34 -0
- data/lib/mindee/product/us/us_mail/us_mail_v2_recipient_address.rb +92 -0
- data/lib/mindee/product/us/us_mail/us_mail_v2_sender_address.rb +78 -0
- data/lib/mindee/product.rb +1 -0
- data/lib/mindee/version.rb +1 -1
- data/lib/mindee.rb +5 -0
- metadata +14 -2
@@ -0,0 +1,72 @@
|
|
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.gsub(%r{[\r\n]}, '')
|
20
|
+
@file = StringIO.new(str_stripped)
|
21
|
+
@file.rewind
|
22
|
+
when Pathname, String
|
23
|
+
@file = if Pathname(input_file).exist?
|
24
|
+
StringIO.new(File.read(input_file, encoding: 'utf-8').gsub(%r{[\r\n]}, ''))
|
25
|
+
else
|
26
|
+
StringIO.new(input_file.gsub(%r{[\r\n]}, ''))
|
27
|
+
end
|
28
|
+
@file.rewind
|
29
|
+
else
|
30
|
+
raise "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
|
39
|
+
JSON.parse(file_str, object_class: Hash)
|
40
|
+
rescue JSON::ParserError
|
41
|
+
raise "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), @file.read)
|
58
|
+
rescue StandardError
|
59
|
+
raise 'Could not get HMAC signature from payload.'
|
60
|
+
end
|
61
|
+
mac
|
62
|
+
end
|
63
|
+
|
64
|
+
# @param secret_key [String] Secret key, either a string or a byte/byte array.
|
65
|
+
# @param signature [String]
|
66
|
+
# @return [Boolean]
|
67
|
+
def valid_hmac_signature?(secret_key, signature)
|
68
|
+
signature == get_hmac_signature(secret_key)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/mindee/input/sources.rb
CHANGED
@@ -166,11 +166,11 @@ module Mindee
|
|
166
166
|
|
167
167
|
# Load a document from a file handle.
|
168
168
|
class FileInputSource < LocalInputSource
|
169
|
-
# @param
|
169
|
+
# @param input_file [File]
|
170
170
|
# @param filename [String]
|
171
171
|
# @param fix_pdf [Boolean]
|
172
|
-
def initialize(
|
173
|
-
io_stream =
|
172
|
+
def initialize(input_file, filename, fix_pdf: false)
|
173
|
+
io_stream = input_file
|
174
174
|
super(io_stream, filename, fix_pdf: fix_pdf)
|
175
175
|
end
|
176
176
|
end
|
@@ -100,7 +100,7 @@ module Mindee
|
|
100
100
|
attr_reader :job
|
101
101
|
# @return [Mindee::Parsing::Common::ApiRequest]
|
102
102
|
attr_reader :api_request
|
103
|
-
# @return [
|
103
|
+
# @return [String]
|
104
104
|
attr_reader :raw_http
|
105
105
|
|
106
106
|
# @param product_class [Class<Mindee::Product>]
|
@@ -108,9 +108,10 @@ module Mindee
|
|
108
108
|
# @param raw_http [String]
|
109
109
|
def initialize(product_class, http_response, raw_http)
|
110
110
|
@raw_http = raw_http.to_s
|
111
|
-
|
112
|
-
|
113
|
-
|
111
|
+
raise 'Invalid response format.' unless http_response.key?('api_request')
|
112
|
+
|
113
|
+
@api_request = Mindee::Parsing::Common::ApiRequest.new(http_response['api_request'])
|
114
|
+
|
114
115
|
if http_response.key?('document') &&
|
115
116
|
(!http_response.key?('job') ||
|
116
117
|
http_response['job']['status'] == 'completed') &&
|
@@ -27,6 +27,22 @@ module Mindee
|
|
27
27
|
end
|
28
28
|
out_str.strip
|
29
29
|
end
|
30
|
+
|
31
|
+
# Constructs a line from a column, located underneath given coordinates
|
32
|
+
# @param coordinates [Array<Mindee::Geometry::Point>] Polygon or bounding box where the reconstruction should
|
33
|
+
# start.
|
34
|
+
# @param page_id [Integer] ID of the page to start at
|
35
|
+
# @param x_margin [Float] Margin of misalignment for the x coordinate.
|
36
|
+
# @return [Mindee::Parsing::Common::Ocr::OcrLine]
|
37
|
+
def reconstruct_vertically(coordinates, page_id, x_margin)
|
38
|
+
line_arr = OcrLine.new([])
|
39
|
+
@pages[page_id].all_lines.each do |line|
|
40
|
+
line.each do |word|
|
41
|
+
line_arr.push(word) if Geometry.below?(word.polygon, coordinates, x_margin / 2, x_margin * 2)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
line_arr
|
45
|
+
end
|
30
46
|
end
|
31
47
|
end
|
32
48
|
end
|
@@ -163,6 +163,16 @@ module Mindee
|
|
163
163
|
def to_s
|
164
164
|
@mvision_v1.to_s
|
165
165
|
end
|
166
|
+
|
167
|
+
# Constructs a line from a column, located underneath given coordinates
|
168
|
+
# @param coordinates [Array<Mindee::Geometry::Point>] Polygon or bounding box where the reconstruction should
|
169
|
+
# start
|
170
|
+
# @param page_id [Integer] ID of the page to start at
|
171
|
+
# @param x_margin [Float] Margin of misalignment for the x coordinate (default 10%)
|
172
|
+
# @return [Mindee::Parsing::Common::Ocr::OcrLine]
|
173
|
+
def reconstruct_vertically(coordinates, page_id, x_margin = 0.05)
|
174
|
+
@mvision_v1.reconstruct_vertically(coordinates, page_id, x_margin)
|
175
|
+
end
|
166
176
|
end
|
167
177
|
end
|
168
178
|
end
|
@@ -89,10 +89,12 @@ module Mindee
|
|
89
89
|
# Feature field object wrapper for specialized methods.
|
90
90
|
class FeatureField < AbstractField
|
91
91
|
# Format strings for display by shortening long strings and assigning empty ones.
|
92
|
-
# @param in_str [String, nil]
|
92
|
+
# @param in_str [String, Boolean, nil]
|
93
93
|
# @param max_col_size [int, nil]
|
94
94
|
# @return [String]
|
95
95
|
def format_for_display(in_str, max_col_size = nil)
|
96
|
+
return 'True' if in_str == true
|
97
|
+
return 'False' if in_str == false
|
96
98
|
return '' if in_str.nil?
|
97
99
|
return in_str if max_col_size.nil?
|
98
100
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'base_field'
|
4
|
+
|
5
|
+
module Mindee
|
6
|
+
module Parsing
|
7
|
+
module Standard
|
8
|
+
# Represents basic text information.
|
9
|
+
class BooleanField < Field
|
10
|
+
# Value as Boolean
|
11
|
+
# @return [Boolean, nil]
|
12
|
+
attr_reader :value
|
13
|
+
|
14
|
+
def initialize(prediction, page_id = nil, reconstructed: false)
|
15
|
+
super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -23,10 +23,10 @@ module Mindee
|
|
23
23
|
|
24
24
|
# @param prediction [Hash]
|
25
25
|
def initialize(prediction, _page_id = nil)
|
26
|
-
value_key = if prediction.include? 'value'
|
27
|
-
'value'
|
28
|
-
else
|
26
|
+
value_key = if !prediction.include?('value') || prediction['value'].nil?
|
29
27
|
'language'
|
28
|
+
else
|
29
|
+
'value'
|
30
30
|
end
|
31
31
|
@confidence = prediction['confidence']
|
32
32
|
@value = prediction[value_key]
|
@@ -38,7 +38,7 @@ module Mindee
|
|
38
38
|
# @return [String]
|
39
39
|
def to_s
|
40
40
|
out_str = String.new
|
41
|
-
out_str << "#{@value}; "
|
41
|
+
out_str << "#{@value}; " unless @value.nil?
|
42
42
|
out_str << "#{@language}; " if @language
|
43
43
|
out_str << "#{@country}; " if @country
|
44
44
|
out_str << "#{@currency}; " if @currency
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative 'standard/amount_field'
|
4
4
|
require_relative 'standard/base_field'
|
5
|
+
require_relative 'standard/boolean_field'
|
5
6
|
require_relative 'standard/classification_field'
|
6
7
|
require_relative 'standard/company_registration_field'
|
7
8
|
require_relative 'standard/date_field'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../parsing'
|
4
|
+
require_relative 'us_mail_v2_document'
|
5
|
+
require_relative 'us_mail_v2_page'
|
6
|
+
|
7
|
+
module Mindee
|
8
|
+
module Product
|
9
|
+
module US
|
10
|
+
# US Mail module.
|
11
|
+
module UsMail
|
12
|
+
# US Mail API version 2 inference prediction.
|
13
|
+
class UsMailV2 < Mindee::Parsing::Common::Inference
|
14
|
+
@endpoint_name = 'us_mail'
|
15
|
+
@endpoint_version = '2'
|
16
|
+
|
17
|
+
# @param prediction [Hash]
|
18
|
+
def initialize(prediction)
|
19
|
+
super
|
20
|
+
@prediction = UsMailV2Document.new(prediction['prediction'], nil)
|
21
|
+
@pages = []
|
22
|
+
prediction['pages'].each do |page|
|
23
|
+
if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
|
24
|
+
@pages.push(UsMailV2Page.new(page))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class << self
|
30
|
+
# Name of the endpoint for this product.
|
31
|
+
# @return [String]
|
32
|
+
attr_reader :endpoint_name
|
33
|
+
# Version for this product.
|
34
|
+
# @return [String]
|
35
|
+
attr_reader :endpoint_version
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../parsing'
|
4
|
+
require_relative 'us_mail_v2_sender_address'
|
5
|
+
require_relative 'us_mail_v2_recipient_address'
|
6
|
+
|
7
|
+
module Mindee
|
8
|
+
module Product
|
9
|
+
module US
|
10
|
+
module UsMail
|
11
|
+
# US Mail API version 2.0 document data.
|
12
|
+
class UsMailV2Document < Mindee::Parsing::Common::Prediction
|
13
|
+
include Mindee::Parsing::Standard
|
14
|
+
# The addresses of the recipients.
|
15
|
+
# @return [Array<Mindee::Product::US::UsMail::UsMailV2RecipientAddress>]
|
16
|
+
attr_reader :recipient_addresses
|
17
|
+
# The names of the recipients.
|
18
|
+
# @return [Array<Mindee::Parsing::Standard::StringField>]
|
19
|
+
attr_reader :recipient_names
|
20
|
+
# The address of the sender.
|
21
|
+
# @return [Mindee::Product::US::UsMail::UsMailV2SenderAddress]
|
22
|
+
attr_reader :sender_address
|
23
|
+
# The name of the sender.
|
24
|
+
# @return [Mindee::Parsing::Standard::StringField]
|
25
|
+
attr_reader :sender_name
|
26
|
+
|
27
|
+
# @param prediction [Hash]
|
28
|
+
# @param page_id [Integer, nil]
|
29
|
+
def initialize(prediction, page_id)
|
30
|
+
super()
|
31
|
+
@recipient_addresses = []
|
32
|
+
prediction['recipient_addresses'].each do |item|
|
33
|
+
@recipient_addresses.push(UsMailV2RecipientAddress.new(item, page_id))
|
34
|
+
end
|
35
|
+
@recipient_names = []
|
36
|
+
prediction['recipient_names'].each do |item|
|
37
|
+
@recipient_names.push(StringField.new(item, page_id))
|
38
|
+
end
|
39
|
+
@sender_address = UsMailV2SenderAddress.new(prediction['sender_address'], page_id)
|
40
|
+
@sender_name = StringField.new(prediction['sender_name'], page_id)
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [String]
|
44
|
+
def to_s
|
45
|
+
sender_address = @sender_address.to_s
|
46
|
+
recipient_names = @recipient_names.join("\n #{' ' * 17}")
|
47
|
+
recipient_addresses = recipient_addresses_to_s
|
48
|
+
out_str = String.new
|
49
|
+
out_str << "\n:Sender Name: #{@sender_name}".rstrip
|
50
|
+
out_str << "\n:Sender Address:"
|
51
|
+
out_str << sender_address
|
52
|
+
out_str << "\n:Recipient Names: #{recipient_names}".rstrip
|
53
|
+
out_str << "\n:Recipient Addresses:"
|
54
|
+
out_str << recipient_addresses
|
55
|
+
out_str[1..].to_s
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# @param char [String]
|
61
|
+
# @return [String]
|
62
|
+
def recipient_addresses_separator(char)
|
63
|
+
out_str = String.new
|
64
|
+
out_str << ' '
|
65
|
+
out_str << "+#{char * 17}"
|
66
|
+
out_str << "+#{char * 37}"
|
67
|
+
out_str << "+#{char * 19}"
|
68
|
+
out_str << "+#{char * 13}"
|
69
|
+
out_str << "+#{char * 24}"
|
70
|
+
out_str << "+#{char * 7}"
|
71
|
+
out_str << "+#{char * 27}"
|
72
|
+
out_str << '+'
|
73
|
+
out_str
|
74
|
+
end
|
75
|
+
|
76
|
+
# @return [String]
|
77
|
+
def recipient_addresses_to_s
|
78
|
+
return '' if @recipient_addresses.empty?
|
79
|
+
|
80
|
+
line_items = @recipient_addresses.map(&:to_table_line).join("\n#{recipient_addresses_separator('-')}\n ")
|
81
|
+
out_str = String.new
|
82
|
+
out_str << "\n#{recipient_addresses_separator('-')}"
|
83
|
+
out_str << "\n |"
|
84
|
+
out_str << ' City |'
|
85
|
+
out_str << ' Complete Address |'
|
86
|
+
out_str << ' Is Address Change |'
|
87
|
+
out_str << ' Postal Code |'
|
88
|
+
out_str << ' Private Mailbox Number |'
|
89
|
+
out_str << ' State |'
|
90
|
+
out_str << ' Street |'
|
91
|
+
out_str << "\n#{recipient_addresses_separator('=')}"
|
92
|
+
out_str << "\n #{line_items}"
|
93
|
+
out_str << "\n#{recipient_addresses_separator('-')}"
|
94
|
+
out_str
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../parsing'
|
4
|
+
require_relative 'us_mail_v2_document'
|
5
|
+
|
6
|
+
module Mindee
|
7
|
+
module Product
|
8
|
+
module US
|
9
|
+
module UsMail
|
10
|
+
# US Mail API version 2.0 page data.
|
11
|
+
class UsMailV2Page < Mindee::Parsing::Common::Page
|
12
|
+
# @param prediction [Hash]
|
13
|
+
def initialize(prediction)
|
14
|
+
super(prediction)
|
15
|
+
@prediction = UsMailV2PagePrediction.new(
|
16
|
+
prediction['prediction'],
|
17
|
+
prediction['id']
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# US Mail V2 page prediction.
|
23
|
+
class UsMailV2PagePrediction < UsMailV2Document
|
24
|
+
# @return [String]
|
25
|
+
def to_s
|
26
|
+
out_str = String.new
|
27
|
+
out_str << "\n#{super}"
|
28
|
+
out_str
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../parsing'
|
4
|
+
|
5
|
+
module Mindee
|
6
|
+
module Product
|
7
|
+
module US
|
8
|
+
module UsMail
|
9
|
+
# The addresses of the recipients.
|
10
|
+
class UsMailV2RecipientAddress < Mindee::Parsing::Standard::FeatureField
|
11
|
+
include Mindee::Parsing::Standard
|
12
|
+
# The city of the recipient's address.
|
13
|
+
# @return [String]
|
14
|
+
attr_reader :city
|
15
|
+
# The complete address of the recipient.
|
16
|
+
# @return [String]
|
17
|
+
attr_reader :complete
|
18
|
+
# Indicates if the recipient's address is a change of address.
|
19
|
+
# @return [Boolean]
|
20
|
+
attr_reader :is_address_change
|
21
|
+
# The postal code of the recipient's address.
|
22
|
+
# @return [String]
|
23
|
+
attr_reader :postal_code
|
24
|
+
# The private mailbox number of the recipient's address.
|
25
|
+
# @return [String]
|
26
|
+
attr_reader :private_mailbox_number
|
27
|
+
# Second part of the ISO 3166-2 code, consisting of two letters indicating the US State.
|
28
|
+
# @return [String]
|
29
|
+
attr_reader :state
|
30
|
+
# The street of the recipient's address.
|
31
|
+
# @return [String]
|
32
|
+
attr_reader :street
|
33
|
+
|
34
|
+
# @param prediction [Hash]
|
35
|
+
# @param page_id [Integer, nil]
|
36
|
+
def initialize(prediction, page_id)
|
37
|
+
super(prediction, page_id)
|
38
|
+
@city = prediction['city']
|
39
|
+
@complete = prediction['complete']
|
40
|
+
@is_address_change = prediction['is_address_change']
|
41
|
+
@postal_code = prediction['postal_code']
|
42
|
+
@private_mailbox_number = prediction['private_mailbox_number']
|
43
|
+
@state = prediction['state']
|
44
|
+
@street = prediction['street']
|
45
|
+
@page_id = page_id
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [Hash]
|
49
|
+
def printable_values
|
50
|
+
printable = {}
|
51
|
+
printable[:city] = format_for_display(@city, 15)
|
52
|
+
printable[:complete] = format_for_display(@complete, 35)
|
53
|
+
printable[:is_address_change] = format_for_display(@is_address_change, nil)
|
54
|
+
printable[:postal_code] = format_for_display(@postal_code, nil)
|
55
|
+
printable[:private_mailbox_number] = format_for_display(@private_mailbox_number, nil)
|
56
|
+
printable[:state] = format_for_display(@state, nil)
|
57
|
+
printable[:street] = format_for_display(@street, 25)
|
58
|
+
printable
|
59
|
+
end
|
60
|
+
|
61
|
+
# @return [String]
|
62
|
+
def to_table_line
|
63
|
+
printable = printable_values
|
64
|
+
out_str = String.new
|
65
|
+
out_str << format('| %- 16s', printable[:city])
|
66
|
+
out_str << format('| %- 36s', printable[:complete])
|
67
|
+
out_str << format('| %- 18s', printable[:is_address_change])
|
68
|
+
out_str << format('| %- 12s', printable[:postal_code])
|
69
|
+
out_str << format('| %- 23s', printable[:private_mailbox_number])
|
70
|
+
out_str << format('| %- 6s', printable[:state])
|
71
|
+
out_str << format('| %- 26s', printable[:street])
|
72
|
+
out_str << '|'
|
73
|
+
end
|
74
|
+
|
75
|
+
# @return [String]
|
76
|
+
def to_s
|
77
|
+
printable = printable_values
|
78
|
+
out_str = String.new
|
79
|
+
out_str << "\n :City: #{printable[:city]}"
|
80
|
+
out_str << "\n :Complete Address: #{printable[:complete]}"
|
81
|
+
out_str << "\n :Is Address Change: #{printable[:is_address_change]}"
|
82
|
+
out_str << "\n :Postal Code: #{printable[:postal_code]}"
|
83
|
+
out_str << "\n :Private Mailbox Number: #{printable[:private_mailbox_number]}"
|
84
|
+
out_str << "\n :State: #{printable[:state]}"
|
85
|
+
out_str << "\n :Street: #{printable[:street]}"
|
86
|
+
out_str
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../parsing'
|
4
|
+
|
5
|
+
module Mindee
|
6
|
+
module Product
|
7
|
+
module US
|
8
|
+
module UsMail
|
9
|
+
# The address of the sender.
|
10
|
+
class UsMailV2SenderAddress < Mindee::Parsing::Standard::FeatureField
|
11
|
+
include Mindee::Parsing::Standard
|
12
|
+
# The city of the sender's address.
|
13
|
+
# @return [String]
|
14
|
+
attr_reader :city
|
15
|
+
# The complete address of the sender.
|
16
|
+
# @return [String]
|
17
|
+
attr_reader :complete
|
18
|
+
# The postal code of the sender's address.
|
19
|
+
# @return [String]
|
20
|
+
attr_reader :postal_code
|
21
|
+
# Second part of the ISO 3166-2 code, consisting of two letters indicating the US State.
|
22
|
+
# @return [String]
|
23
|
+
attr_reader :state
|
24
|
+
# The street of the sender's address.
|
25
|
+
# @return [String]
|
26
|
+
attr_reader :street
|
27
|
+
|
28
|
+
# @param prediction [Hash]
|
29
|
+
# @param page_id [Integer, nil]
|
30
|
+
def initialize(prediction, page_id)
|
31
|
+
super(prediction, page_id)
|
32
|
+
@city = prediction['city']
|
33
|
+
@complete = prediction['complete']
|
34
|
+
@postal_code = prediction['postal_code']
|
35
|
+
@state = prediction['state']
|
36
|
+
@street = prediction['street']
|
37
|
+
@page_id = page_id
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Hash]
|
41
|
+
def printable_values
|
42
|
+
printable = {}
|
43
|
+
printable[:city] = format_for_display(@city, 15)
|
44
|
+
printable[:complete] = format_for_display(@complete, 35)
|
45
|
+
printable[:postal_code] = format_for_display(@postal_code, nil)
|
46
|
+
printable[:state] = format_for_display(@state, nil)
|
47
|
+
printable[:street] = format_for_display(@street, 25)
|
48
|
+
printable
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [String]
|
52
|
+
def to_table_line
|
53
|
+
printable = printable_values
|
54
|
+
out_str = String.new
|
55
|
+
out_str << format('| %- 16s', printable[:city])
|
56
|
+
out_str << format('| %- 36s', printable[:complete])
|
57
|
+
out_str << format('| %- 12s', printable[:postal_code])
|
58
|
+
out_str << format('| %- 6s', printable[:state])
|
59
|
+
out_str << format('| %- 26s', printable[:street])
|
60
|
+
out_str << '|'
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [String]
|
64
|
+
def to_s
|
65
|
+
printable = printable_values
|
66
|
+
out_str = String.new
|
67
|
+
out_str << "\n :City: #{printable[:city]}"
|
68
|
+
out_str << "\n :Complete Address: #{printable[:complete]}"
|
69
|
+
out_str << "\n :Postal Code: #{printable[:postal_code]}"
|
70
|
+
out_str << "\n :State: #{printable[:state]}"
|
71
|
+
out_str << "\n :Street: #{printable[:street]}"
|
72
|
+
out_str
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/mindee/product.rb
CHANGED
@@ -26,4 +26,5 @@ require_relative 'product/international_id/international_id_v2'
|
|
26
26
|
require_relative 'product/resume/resume_v1'
|
27
27
|
require_relative 'product/us/bank_check/bank_check_v1'
|
28
28
|
require_relative 'product/us/driver_license/driver_license_v1'
|
29
|
+
require_relative 'product/us/us_mail/us_mail_v2'
|
29
30
|
require_relative 'product/us/w9/w9_v1'
|
data/lib/mindee/version.rb
CHANGED
data/lib/mindee.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'mindee/client'
|
4
|
+
require 'mindee/extraction'
|
4
5
|
|
5
6
|
module Mindee
|
6
7
|
# Mindee internal http module.
|
@@ -18,6 +19,10 @@ module Mindee
|
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
22
|
+
# Custom extraction module
|
23
|
+
module Extraction
|
24
|
+
end
|
25
|
+
|
21
26
|
# Parsing internals and fields.
|
22
27
|
module Parsing
|
23
28
|
# Common fields and functions.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mindee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mindee, SA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: marcel
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- docs/code_samples/proof_of_address_v1.txt
|
151
151
|
- docs/code_samples/resume_v1_async.txt
|
152
152
|
- docs/code_samples/us_driver_license_v1.txt
|
153
|
+
- docs/code_samples/us_mail_v2_async.txt
|
153
154
|
- docs/code_samples/us_w9_v1.txt
|
154
155
|
- docs/cropper_v1.md
|
155
156
|
- docs/custom_v1.md
|
@@ -168,9 +169,13 @@ files:
|
|
168
169
|
- docs/proof_of_address_v1.md
|
169
170
|
- docs/resume_v1.md
|
170
171
|
- docs/us_driver_license_v1.md
|
172
|
+
- docs/us_mail_v2.md
|
171
173
|
- docs/us_w9_v1.md
|
172
174
|
- lib/mindee.rb
|
173
175
|
- lib/mindee/client.rb
|
176
|
+
- lib/mindee/extraction.rb
|
177
|
+
- lib/mindee/extraction/ocr_extractor.rb
|
178
|
+
- lib/mindee/extraction/tax_extractor.rb
|
174
179
|
- lib/mindee/geometry.rb
|
175
180
|
- lib/mindee/geometry/min_max.rb
|
176
181
|
- lib/mindee/geometry/point.rb
|
@@ -183,6 +188,7 @@ files:
|
|
183
188
|
- lib/mindee/http/error.rb
|
184
189
|
- lib/mindee/http/response_validation.rb
|
185
190
|
- lib/mindee/input.rb
|
191
|
+
- lib/mindee/input/local_response.rb
|
186
192
|
- lib/mindee/input/sources.rb
|
187
193
|
- lib/mindee/parsing.rb
|
188
194
|
- lib/mindee/parsing/common.rb
|
@@ -205,6 +211,7 @@ files:
|
|
205
211
|
- lib/mindee/parsing/standard.rb
|
206
212
|
- lib/mindee/parsing/standard/amount_field.rb
|
207
213
|
- lib/mindee/parsing/standard/base_field.rb
|
214
|
+
- lib/mindee/parsing/standard/boolean_field.rb
|
208
215
|
- lib/mindee/parsing/standard/classification_field.rb
|
209
216
|
- lib/mindee/parsing/standard/company_registration_field.rb
|
210
217
|
- lib/mindee/parsing/standard/date_field.rb
|
@@ -307,6 +314,11 @@ files:
|
|
307
314
|
- lib/mindee/product/us/driver_license/driver_license_v1.rb
|
308
315
|
- lib/mindee/product/us/driver_license/driver_license_v1_document.rb
|
309
316
|
- lib/mindee/product/us/driver_license/driver_license_v1_page.rb
|
317
|
+
- lib/mindee/product/us/us_mail/us_mail_v2.rb
|
318
|
+
- lib/mindee/product/us/us_mail/us_mail_v2_document.rb
|
319
|
+
- lib/mindee/product/us/us_mail/us_mail_v2_page.rb
|
320
|
+
- lib/mindee/product/us/us_mail/us_mail_v2_recipient_address.rb
|
321
|
+
- lib/mindee/product/us/us_mail/us_mail_v2_sender_address.rb
|
310
322
|
- lib/mindee/product/us/w9/w9_v1.rb
|
311
323
|
- lib/mindee/product/us/w9/w9_v1_document.rb
|
312
324
|
- lib/mindee/product/us/w9/w9_v1_page.rb
|