Skip to content

Commit 7e106bc

Browse files
✨ add support for full address fields (#244)
1 parent 524c222 commit 7e106bc

File tree

7 files changed

+151
-18
lines changed

7 files changed

+151
-18
lines changed

docs/financial_document_v1.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ public class SimpleMindeeClient {
107107
########
108108
Document
109109
########
110-
:Mindee ID: f52333ab-811e-4647-993e-ad79e072afa3
110+
:Mindee ID: 6dd26385-719b-4527-bf6f-87d9da619de5
111111
:Filename: default_sample.jpg
112112
113113
Inference
114114
#########
115-
:Product: mindee/financial_document v1.12
115+
:Product: mindee/financial_document v1.14
116116
:Rotation applied: Yes
117117
118118
Prediction
@@ -237,6 +237,21 @@ A typical `BaseField` object will have the following attributes:
237237

238238
Aside from the previous attributes, all basic fields have access to a custom `toString` method that can be used to print their value as a string.
239239

240+
241+
### AddressField
242+
Aside from the basic `BaseField` attributes, the address field `AddressField` also implements the following:
243+
244+
* **streetNumber** (`string`): String representation of the string number. Can be `null`.
245+
* **streetName** (`string`): Name of the street. Can be `null`.
246+
* **poBox** (`string`): String representation of the PO Box number. Can be `null`.
247+
* **addressComplement** (`string`): Address complement. Can be `null`.
248+
* **city** (`string`): City name. Can be `null`.
249+
* **postalcode** (`string`): String representation of the postal code. Can be `null`.
250+
* **state** (`string`): State name. Can be `null`.
251+
* **country** (`string`): Country name. Can be `null`.
252+
253+
Note: The `value` field of an AddressField should be a concatenation of the rest of the values.
254+
240255
### AmountField
241256
An amount field `AmountField` extends `BaseField`, but also implements:
242257
* **value** (`Double`): corresponds to the field value. Can be `null` if no value was extracted.

docs/invoices_v4.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ public class SimpleMindeeClient {
107107
########
108108
Document
109109
########
110-
:Mindee ID: 3e524d26-f7dc-4852-9bbf-833a127a9570
110+
:Mindee ID: 744748d5-9051-461c-b70c-bbf81f5ff943
111111
:Filename: default_sample.jpg
112112
113113
Inference
114114
#########
115-
:Product: mindee/invoices v4.10
115+
:Product: mindee/invoices v4.11
116116
:Rotation applied: Yes
117117
118118
Prediction
@@ -148,6 +148,8 @@ Prediction
148148
:Billing Address: 1954 Bloor Street West Toronto, ON, M6P 3K9 Canada
149149
:Document Type: INVOICE
150150
:Document Type Extended: INVOICE
151+
:Purchase Subcategory:
152+
:Purchase Category: miscellaneous
151153
:Line Items:
152154
+--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+
153155
| Description | Product code | Quantity | Tax Amount | Tax Rate (%) | Total Amount | Unit of measure | Unit Price |
@@ -195,6 +197,8 @@ Page 0
195197
:Billing Address: 1954 Bloor Street West Toronto, ON, M6P 3K9 Canada
196198
:Document Type: INVOICE
197199
:Document Type Extended: INVOICE
200+
:Purchase Subcategory:
201+
:Purchase Category: miscellaneous
198202
:Line Items:
199203
+--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+
200204
| Description | Product code | Quantity | Tax Amount | Tax Rate (%) | Total Amount | Unit of measure | Unit Price |
@@ -225,6 +229,21 @@ A typical `BaseField` object will have the following attributes:
225229

226230
Aside from the previous attributes, all basic fields have access to a custom `toString` method that can be used to print their value as a string.
227231

232+
233+
### AddressField
234+
Aside from the basic `BaseField` attributes, the address field `AddressField` also implements the following:
235+
236+
* **streetNumber** (`string`): String representation of the string number. Can be `null`.
237+
* **streetName** (`string`): Name of the street. Can be `null`.
238+
* **poBox** (`string`): String representation of the PO Box number. Can be `null`.
239+
* **addressComplement** (`string`): Address complement. Can be `null`.
240+
* **city** (`string`): City name. Can be `null`.
241+
* **postalcode** (`string`): String representation of the postal code. Can be `null`.
242+
* **state** (`string`): State name. Can be `null`.
243+
* **country** (`string`): Country name. Can be `null`.
244+
245+
Note: The `value` field of an AddressField should be a concatenation of the rest of the values.
246+
228247
### AmountField
229248
An amount field `AmountField` extends `BaseField`, but also implements:
230249
* **value** (`Double`): corresponds to the field value. Can be `null` if no value was extracted.

docs/us_healthcare_cards_v1.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,18 @@ public class SimpleMindeeClient {
6060
########
6161
Document
6262
########
63-
:Mindee ID: 1e71d5f0-dedb-4070-9d94-9207cd9570b5
63+
:Mindee ID: 5e917fc8-5c13-42b2-967f-954f4eed9959
6464
:Filename: default_sample.jpg
6565
6666
Inference
6767
#########
68-
:Product: mindee/us_healthcare_cards v1.2
68+
:Product: mindee/us_healthcare_cards v1.3
6969
:Rotation applied: Yes
7070
7171
Prediction
7272
==========
7373
:Company Name: UnitedHealthcare
74+
:Plan Name: Choice Plus
7475
:Member Name: SUBSCRIBER SMITH
7576
:Member ID: 123456789
7677
:Issuer 80840:
@@ -84,14 +85,14 @@ Prediction
8485
:RX ID:
8586
:RX GRP: UHEALTH
8687
:RX PCN: 9999
87-
:copays:
88+
:Copays:
8889
+--------------+----------------------+
8990
| Service Fees | Service Name |
9091
+==============+======================+
91-
| 300.00 | emergency_room |
92-
+--------------+----------------------+
9392
| 20.00 | office_visit |
9493
+--------------+----------------------+
94+
| 300.00 | emergency_room |
95+
+--------------+----------------------+
9596
| 75.00 | urgent_care |
9697
+--------------+----------------------+
9798
| 30.00 | specialist |
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.mindee.parsing.standard;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
6+
import com.mindee.geometry.Polygon;
7+
import com.mindee.geometry.PolygonDeserializer;
8+
import lombok.Getter;
9+
10+
/**
11+
* Represent a postal address field broken down into its individual components.
12+
*/
13+
@Getter
14+
@JsonIgnoreProperties(ignoreUnknown = true)
15+
public final class AddressField extends StringField {
16+
/** The address exactly as it appears on the document. */
17+
private final String rawValue;
18+
19+
/** Street number. */
20+
private final String streetNumber;
21+
22+
/** Street name. */
23+
private final String streetName;
24+
25+
/** PO-box number. */
26+
private final String poBox;
27+
28+
/** Additional address complement. */
29+
private final String addressComplement;
30+
31+
/** City or locality. */
32+
private final String city;
33+
34+
/** Postal or ZIP code. */
35+
private final String postalCode;
36+
37+
/** State, province or region. */
38+
private final String state;
39+
40+
/** Country. */
41+
private final String country;
42+
43+
public AddressField(
44+
@JsonProperty("value")
45+
String value,
46+
@JsonProperty("raw_value")
47+
String rawValue,
48+
@JsonProperty("street_number")
49+
String streetNumber,
50+
@JsonProperty("street_name")
51+
String streetName,
52+
@JsonProperty("po_box")
53+
String poBox,
54+
@JsonProperty("address_complement")
55+
String addressComplement,
56+
@JsonProperty("city")
57+
String city,
58+
@JsonProperty("postal_code")
59+
String postalCode,
60+
@JsonProperty("state")
61+
String state,
62+
@JsonProperty("country")
63+
String country,
64+
@JsonProperty("confidence")
65+
Double confidence,
66+
@JsonProperty("polygon")
67+
@JsonDeserialize(using = PolygonDeserializer.class)
68+
Polygon polygon,
69+
@JsonProperty("page_id")
70+
Integer pageId
71+
) {
72+
super(value, rawValue, confidence, polygon, pageId);
73+
this.rawValue = rawValue;
74+
this.streetNumber = streetNumber;
75+
this.streetName = streetName;
76+
this.poBox = poBox;
77+
this.addressComplement = addressComplement;
78+
this.city = city;
79+
this.postalCode = postalCode;
80+
this.state = state;
81+
this.country = country;
82+
}
83+
84+
/**
85+
* Address field constructor only containing the value.
86+
*/
87+
public AddressField(
88+
String value,
89+
Double confidence,
90+
Polygon polygon
91+
) {
92+
this(value, null, null, null, null,
93+
null, null, null, null, null,
94+
confidence, polygon, null);
95+
}
96+
}

src/main/java/com/mindee/parsing/standard/StringField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
@Getter
1515
@JsonIgnoreProperties(ignoreUnknown = true)
16-
public final class StringField extends BaseField {
16+
public class StringField extends BaseField {
1717

1818
/**
1919
* The value of the field.

src/main/java/com/mindee/product/financialdocument/FinancialDocumentV1Document.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
66
import com.mindee.parsing.SummaryHelper;
77
import com.mindee.parsing.common.Prediction;
8+
import com.mindee.parsing.standard.AddressField;
89
import com.mindee.parsing.standard.AmountField;
910
import com.mindee.parsing.standard.ClassificationField;
1011
import com.mindee.parsing.standard.CompanyRegistrationField;
@@ -31,7 +32,7 @@ public class FinancialDocumentV1Document extends Prediction {
3132
* The customer's address used for billing.
3233
*/
3334
@JsonProperty("billing_address")
34-
protected StringField billingAddress;
35+
protected AddressField billingAddress;
3536
/**
3637
* The purchase category.
3738
*/
@@ -41,7 +42,7 @@ public class FinancialDocumentV1Document extends Prediction {
4142
* The address of the customer.
4243
*/
4344
@JsonProperty("customer_address")
44-
protected StringField customerAddress;
45+
protected AddressField customerAddress;
4546
/**
4647
* List of company registration numbers associated to the customer.
4748
*/
@@ -121,7 +122,7 @@ public class FinancialDocumentV1Document extends Prediction {
121122
* The customer's address used for shipping.
122123
*/
123124
@JsonProperty("shipping_address")
124-
protected StringField shippingAddress;
125+
protected AddressField shippingAddress;
125126
/**
126127
* The purchase subcategory for transport, food and shooping.
127128
*/
@@ -131,7 +132,7 @@ public class FinancialDocumentV1Document extends Prediction {
131132
* The address of the supplier or merchant.
132133
*/
133134
@JsonProperty("supplier_address")
134-
protected StringField supplierAddress;
135+
protected AddressField supplierAddress;
135136
/**
136137
* List of company registration numbers associated to the supplier.
137138
*/

src/main/java/com/mindee/product/invoice/InvoiceV4Document.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
66
import com.mindee.parsing.SummaryHelper;
77
import com.mindee.parsing.common.Prediction;
8+
import com.mindee.parsing.standard.AddressField;
89
import com.mindee.parsing.standard.AmountField;
910
import com.mindee.parsing.standard.ClassificationField;
1011
import com.mindee.parsing.standard.CompanyRegistrationField;
@@ -31,7 +32,7 @@ public class InvoiceV4Document extends Prediction {
3132
* The customer billing address.
3233
*/
3334
@JsonProperty("billing_address")
34-
protected StringField billingAddress;
35+
protected AddressField billingAddress;
3536
/**
3637
* The purchase category.
3738
*/
@@ -41,7 +42,7 @@ public class InvoiceV4Document extends Prediction {
4142
* The address of the customer.
4243
*/
4344
@JsonProperty("customer_address")
44-
protected StringField customerAddress;
45+
protected AddressField customerAddress;
4546
/**
4647
* List of company registration numbers associated to the customer.
4748
*/
@@ -111,7 +112,7 @@ public class InvoiceV4Document extends Prediction {
111112
* Customer's delivery address.
112113
*/
113114
@JsonProperty("shipping_address")
114-
protected StringField shippingAddress;
115+
protected AddressField shippingAddress;
115116
/**
116117
* The purchase subcategory for transport, food and shopping.
117118
*/
@@ -121,7 +122,7 @@ public class InvoiceV4Document extends Prediction {
121122
* The address of the supplier or merchant.
122123
*/
123124
@JsonProperty("supplier_address")
124-
protected StringField supplierAddress;
125+
protected AddressField supplierAddress;
125126
/**
126127
* List of company registration numbers associated to the supplier.
127128
*/

0 commit comments

Comments
 (0)