From 68d61f7ac6c8e324fef545bb9031eca76598b4d9 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Wed, 28 May 2025 17:40:32 +0200 Subject: [PATCH 1/4] add AddressField implementation --- .../mindee/parsing/standard/AddressField.java | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 src/main/java/com/mindee/parsing/standard/AddressField.java diff --git a/src/main/java/com/mindee/parsing/standard/AddressField.java b/src/main/java/com/mindee/parsing/standard/AddressField.java new file mode 100644 index 000000000..21b5a7892 --- /dev/null +++ b/src/main/java/com/mindee/parsing/standard/AddressField.java @@ -0,0 +1,114 @@ +package com.mindee.parsing.standard; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.mindee.geometry.Polygon; +import com.mindee.geometry.PolygonDeserializer; +import com.mindee.parsing.SummaryHelper; +import lombok.Getter; + +/** + * Represent a postal address field broken down into its individual components. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public final class AddressField extends BaseField { + + /** The full address as a single string. */ + private final String value; + + /** The address exactly as it appears on the document. */ + private final String rawValue; + + /** Street number. */ + private final String streetNumber; + + /** Street name. */ + private final String streetName; + + /** PO-box number. */ + private final String poBox; + + /** Additional address complement. */ + private final String addressComplement; + + /** City or locality. */ + private final String city; + + /** Postal or ZIP code. */ + private final String postalCode; + + /** State, province or region. */ + private final String state; + + /** Country. */ + private final String country; + + public AddressField( + @JsonProperty("value") + String value, + @JsonProperty("raw_value") + String rawValue, + @JsonProperty("street_number") + String streetNumber, + @JsonProperty("street_name") + String streetName, + @JsonProperty("po_box") + String poBox, + @JsonProperty("address_complement") + String addressComplement, + @JsonProperty("city") + String city, + @JsonProperty("postal_code") + String postalCode, + @JsonProperty("state") + String state, + @JsonProperty("country") + String country, + @JsonProperty("confidence") + Double confidence, + @JsonProperty("polygon") + @JsonDeserialize(using = PolygonDeserializer.class) + Polygon polygon, + @JsonProperty("page_id") + Integer pageId + ) { + super(confidence, polygon, pageId); + this.value = value; + this.rawValue = rawValue; + this.streetNumber = streetNumber; + this.streetName = streetName; + this.poBox = poBox; + this.addressComplement = addressComplement; + this.city = city; + this.postalCode = postalCode; + this.state = state; + this.country = country; + } + + /** + * Address field constructor only containing the value. + */ + public AddressField( + String value, + Double confidence, + Polygon polygon + ) { + this(value, null, null, null, null, + null, null, null, null, null, + confidence, polygon, null); + } + + /** + * The field is considered empty when the full value is either null or empty. + */ + public boolean isEmpty() { + return value == null || value.isEmpty(); + } + + @Override + public String toString() { + return SummaryHelper.formatString(this.value); + } +} From 2124d619653fd78ffffa67fa17fb14084f265bfd Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Wed, 28 May 2025 17:45:56 +0200 Subject: [PATCH 2/4] :sparkles: add support for full address fields --- docs/financial_document_v1.md | 19 +++++++++++++-- docs/invoices_v4.md | 23 +++++++++++++++++-- docs/us_healthcare_cards_v1.md | 11 +++++---- .../FinancialDocumentV1Document.java | 9 ++++---- .../product/invoice/InvoiceV4Document.java | 9 ++++---- 5 files changed, 54 insertions(+), 17 deletions(-) diff --git a/docs/financial_document_v1.md b/docs/financial_document_v1.md index 6a30b4dd1..7cc15f25d 100644 --- a/docs/financial_document_v1.md +++ b/docs/financial_document_v1.md @@ -107,12 +107,12 @@ public class SimpleMindeeClient { ######## Document ######## -:Mindee ID: f52333ab-811e-4647-993e-ad79e072afa3 +:Mindee ID: 6dd26385-719b-4527-bf6f-87d9da619de5 :Filename: default_sample.jpg Inference ######### -:Product: mindee/financial_document v1.12 +:Product: mindee/financial_document v1.14 :Rotation applied: Yes Prediction @@ -237,6 +237,21 @@ A typical `BaseField` object will have the following attributes: 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. + +### AddressField +Aside from the basic `BaseField` attributes, the address field `AddressField` also implements the following: + +* **streetNumber** (`str`): String representation of the string number. Can be `null`. +* **streetName** (`str`): Name of the street. Can be `null`. +* **poBox** (`str`): String representation of the PO Box number. Can be `null`. +* **addressComplement** (`str`): Address complement. Can be `null`. +* **city** (`str`): City name. Can be `null`. +* **postalcode** (`str`): String representation of the postal code. Can be `null`. +* **state** (`str`): State name. Can be `null`. +* **country** (`str`): Country name. Can be `null`. + +Note: The `value` field of an AddressField should be a concatenation of the rest of the values. + ### AmountField An amount field `AmountField` extends `BaseField`, but also implements: * **value** (`Double`): corresponds to the field value. Can be `null` if no value was extracted. diff --git a/docs/invoices_v4.md b/docs/invoices_v4.md index b5fc4210a..4d15d8725 100644 --- a/docs/invoices_v4.md +++ b/docs/invoices_v4.md @@ -107,12 +107,12 @@ public class SimpleMindeeClient { ######## Document ######## -:Mindee ID: 3e524d26-f7dc-4852-9bbf-833a127a9570 +:Mindee ID: 744748d5-9051-461c-b70c-bbf81f5ff943 :Filename: default_sample.jpg Inference ######### -:Product: mindee/invoices v4.10 +:Product: mindee/invoices v4.11 :Rotation applied: Yes Prediction @@ -148,6 +148,8 @@ Prediction :Billing Address: 1954 Bloor Street West Toronto, ON, M6P 3K9 Canada :Document Type: INVOICE :Document Type Extended: INVOICE +:Purchase Subcategory: +:Purchase Category: miscellaneous :Line Items: +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ | Description | Product code | Quantity | Tax Amount | Tax Rate (%) | Total Amount | Unit of measure | Unit Price | @@ -195,6 +197,8 @@ Page 0 :Billing Address: 1954 Bloor Street West Toronto, ON, M6P 3K9 Canada :Document Type: INVOICE :Document Type Extended: INVOICE +:Purchase Subcategory: +:Purchase Category: miscellaneous :Line Items: +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ | 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: 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. + +### AddressField +Aside from the basic `BaseField` attributes, the address field `AddressField` also implements the following: + +* **streetNumber** (`str`): String representation of the string number. Can be `null`. +* **streetName** (`str`): Name of the street. Can be `null`. +* **poBox** (`str`): String representation of the PO Box number. Can be `null`. +* **addressComplement** (`str`): Address complement. Can be `null`. +* **city** (`str`): City name. Can be `null`. +* **postalcode** (`str`): String representation of the postal code. Can be `null`. +* **state** (`str`): State name. Can be `null`. +* **country** (`str`): Country name. Can be `null`. + +Note: The `value` field of an AddressField should be a concatenation of the rest of the values. + ### AmountField An amount field `AmountField` extends `BaseField`, but also implements: * **value** (`Double`): corresponds to the field value. Can be `null` if no value was extracted. diff --git a/docs/us_healthcare_cards_v1.md b/docs/us_healthcare_cards_v1.md index d32f08906..e0f403248 100644 --- a/docs/us_healthcare_cards_v1.md +++ b/docs/us_healthcare_cards_v1.md @@ -60,17 +60,18 @@ public class SimpleMindeeClient { ######## Document ######## -:Mindee ID: 1e71d5f0-dedb-4070-9d94-9207cd9570b5 +:Mindee ID: 5e917fc8-5c13-42b2-967f-954f4eed9959 :Filename: default_sample.jpg Inference ######### -:Product: mindee/us_healthcare_cards v1.2 +:Product: mindee/us_healthcare_cards v1.3 :Rotation applied: Yes Prediction ========== :Company Name: UnitedHealthcare +:Plan Name: Choice Plus :Member Name: SUBSCRIBER SMITH :Member ID: 123456789 :Issuer 80840: @@ -84,14 +85,14 @@ Prediction :RX ID: :RX GRP: UHEALTH :RX PCN: 9999 -:copays: +:Copays: +--------------+----------------------+ | Service Fees | Service Name | +==============+======================+ - | 300.00 | emergency_room | - +--------------+----------------------+ | 20.00 | office_visit | +--------------+----------------------+ + | 300.00 | emergency_room | + +--------------+----------------------+ | 75.00 | urgent_care | +--------------+----------------------+ | 30.00 | specialist | diff --git a/src/main/java/com/mindee/product/financialdocument/FinancialDocumentV1Document.java b/src/main/java/com/mindee/product/financialdocument/FinancialDocumentV1Document.java index 8e80bd9f8..925b8c6eb 100644 --- a/src/main/java/com/mindee/product/financialdocument/FinancialDocumentV1Document.java +++ b/src/main/java/com/mindee/product/financialdocument/FinancialDocumentV1Document.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.mindee.parsing.SummaryHelper; import com.mindee.parsing.common.Prediction; +import com.mindee.parsing.standard.AddressField; import com.mindee.parsing.standard.AmountField; import com.mindee.parsing.standard.ClassificationField; import com.mindee.parsing.standard.CompanyRegistrationField; @@ -31,7 +32,7 @@ public class FinancialDocumentV1Document extends Prediction { * The customer's address used for billing. */ @JsonProperty("billing_address") - protected StringField billingAddress; + protected AddressField billingAddress; /** * The purchase category. */ @@ -41,7 +42,7 @@ public class FinancialDocumentV1Document extends Prediction { * The address of the customer. */ @JsonProperty("customer_address") - protected StringField customerAddress; + protected AddressField customerAddress; /** * List of company registration numbers associated to the customer. */ @@ -121,7 +122,7 @@ public class FinancialDocumentV1Document extends Prediction { * The customer's address used for shipping. */ @JsonProperty("shipping_address") - protected StringField shippingAddress; + protected AddressField shippingAddress; /** * The purchase subcategory for transport, food and shooping. */ @@ -131,7 +132,7 @@ public class FinancialDocumentV1Document extends Prediction { * The address of the supplier or merchant. */ @JsonProperty("supplier_address") - protected StringField supplierAddress; + protected AddressField supplierAddress; /** * List of company registration numbers associated to the supplier. */ diff --git a/src/main/java/com/mindee/product/invoice/InvoiceV4Document.java b/src/main/java/com/mindee/product/invoice/InvoiceV4Document.java index 4118bcec3..d10fe124f 100644 --- a/src/main/java/com/mindee/product/invoice/InvoiceV4Document.java +++ b/src/main/java/com/mindee/product/invoice/InvoiceV4Document.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.mindee.parsing.SummaryHelper; import com.mindee.parsing.common.Prediction; +import com.mindee.parsing.standard.AddressField; import com.mindee.parsing.standard.AmountField; import com.mindee.parsing.standard.ClassificationField; import com.mindee.parsing.standard.CompanyRegistrationField; @@ -31,7 +32,7 @@ public class InvoiceV4Document extends Prediction { * The customer billing address. */ @JsonProperty("billing_address") - protected StringField billingAddress; + protected AddressField billingAddress; /** * The purchase category. */ @@ -41,7 +42,7 @@ public class InvoiceV4Document extends Prediction { * The address of the customer. */ @JsonProperty("customer_address") - protected StringField customerAddress; + protected AddressField customerAddress; /** * List of company registration numbers associated to the customer. */ @@ -111,7 +112,7 @@ public class InvoiceV4Document extends Prediction { * Customer's delivery address. */ @JsonProperty("shipping_address") - protected StringField shippingAddress; + protected AddressField shippingAddress; /** * The purchase subcategory for transport, food and shopping. */ @@ -121,7 +122,7 @@ public class InvoiceV4Document extends Prediction { * The address of the supplier or merchant. */ @JsonProperty("supplier_address") - protected StringField supplierAddress; + protected AddressField supplierAddress; /** * List of company registration numbers associated to the supplier. */ From 6b3ce36b0126ef115c1feb365b0da9b5f854f695 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Wed, 28 May 2025 18:03:13 +0200 Subject: [PATCH 3/4] make AddressField properly inherit from StringField --- .../mindee/parsing/standard/AddressField.java | 22 ++----------------- .../mindee/parsing/standard/StringField.java | 2 +- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/mindee/parsing/standard/AddressField.java b/src/main/java/com/mindee/parsing/standard/AddressField.java index 21b5a7892..33da5570d 100644 --- a/src/main/java/com/mindee/parsing/standard/AddressField.java +++ b/src/main/java/com/mindee/parsing/standard/AddressField.java @@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.mindee.geometry.Polygon; import com.mindee.geometry.PolygonDeserializer; -import com.mindee.parsing.SummaryHelper; import lombok.Getter; /** @@ -13,11 +12,7 @@ */ @Getter @JsonIgnoreProperties(ignoreUnknown = true) -public final class AddressField extends BaseField { - - /** The full address as a single string. */ - private final String value; - +public final class AddressField extends StringField { /** The address exactly as it appears on the document. */ private final String rawValue; @@ -74,8 +69,7 @@ public AddressField( @JsonProperty("page_id") Integer pageId ) { - super(confidence, polygon, pageId); - this.value = value; + super(value, rawValue, confidence, polygon, pageId); this.rawValue = rawValue; this.streetNumber = streetNumber; this.streetName = streetName; @@ -99,16 +93,4 @@ public AddressField( null, null, null, null, null, confidence, polygon, null); } - - /** - * The field is considered empty when the full value is either null or empty. - */ - public boolean isEmpty() { - return value == null || value.isEmpty(); - } - - @Override - public String toString() { - return SummaryHelper.formatString(this.value); - } } diff --git a/src/main/java/com/mindee/parsing/standard/StringField.java b/src/main/java/com/mindee/parsing/standard/StringField.java index f46f6c726..3f3707a68 100644 --- a/src/main/java/com/mindee/parsing/standard/StringField.java +++ b/src/main/java/com/mindee/parsing/standard/StringField.java @@ -13,7 +13,7 @@ */ @Getter @JsonIgnoreProperties(ignoreUnknown = true) -public final class StringField extends BaseField { +public class StringField extends BaseField { /** * The value of the field. From d59ef14a348e9f11fc4a12148308cc6c167e2300 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Wed, 28 May 2025 18:43:49 +0200 Subject: [PATCH 4/4] fix typos --- docs/financial_document_v1.md | 16 ++++++++-------- docs/invoices_v4.md | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/financial_document_v1.md b/docs/financial_document_v1.md index 7cc15f25d..0633cf240 100644 --- a/docs/financial_document_v1.md +++ b/docs/financial_document_v1.md @@ -241,14 +241,14 @@ Aside from the previous attributes, all basic fields have access to a custom `to ### AddressField Aside from the basic `BaseField` attributes, the address field `AddressField` also implements the following: -* **streetNumber** (`str`): String representation of the string number. Can be `null`. -* **streetName** (`str`): Name of the street. Can be `null`. -* **poBox** (`str`): String representation of the PO Box number. Can be `null`. -* **addressComplement** (`str`): Address complement. Can be `null`. -* **city** (`str`): City name. Can be `null`. -* **postalcode** (`str`): String representation of the postal code. Can be `null`. -* **state** (`str`): State name. Can be `null`. -* **country** (`str`): Country name. Can be `null`. +* **streetNumber** (`string`): String representation of the string number. Can be `null`. +* **streetName** (`string`): Name of the street. Can be `null`. +* **poBox** (`string`): String representation of the PO Box number. Can be `null`. +* **addressComplement** (`string`): Address complement. Can be `null`. +* **city** (`string`): City name. Can be `null`. +* **postalcode** (`string`): String representation of the postal code. Can be `null`. +* **state** (`string`): State name. Can be `null`. +* **country** (`string`): Country name. Can be `null`. Note: The `value` field of an AddressField should be a concatenation of the rest of the values. diff --git a/docs/invoices_v4.md b/docs/invoices_v4.md index 4d15d8725..d6c64649f 100644 --- a/docs/invoices_v4.md +++ b/docs/invoices_v4.md @@ -233,14 +233,14 @@ Aside from the previous attributes, all basic fields have access to a custom `to ### AddressField Aside from the basic `BaseField` attributes, the address field `AddressField` also implements the following: -* **streetNumber** (`str`): String representation of the string number. Can be `null`. -* **streetName** (`str`): Name of the street. Can be `null`. -* **poBox** (`str`): String representation of the PO Box number. Can be `null`. -* **addressComplement** (`str`): Address complement. Can be `null`. -* **city** (`str`): City name. Can be `null`. -* **postalcode** (`str`): String representation of the postal code. Can be `null`. -* **state** (`str`): State name. Can be `null`. -* **country** (`str`): Country name. Can be `null`. +* **streetNumber** (`string`): String representation of the string number. Can be `null`. +* **streetName** (`string`): Name of the street. Can be `null`. +* **poBox** (`string`): String representation of the PO Box number. Can be `null`. +* **addressComplement** (`string`): Address complement. Can be `null`. +* **city** (`string`): City name. Can be `null`. +* **postalcode** (`string`): String representation of the postal code. Can be `null`. +* **state** (`string`): State name. Can be `null`. +* **country** (`string`): Country name. Can be `null`. Note: The `value` field of an AddressField should be a concatenation of the rest of the values.