diff --git a/docs/code_samples/us_mail_v2_async.txt b/docs/code_samples/us_mail_v2_async.txt deleted file mode 100644 index 08076924a..000000000 --- a/docs/code_samples/us_mail_v2_async.txt +++ /dev/null @@ -1,41 +0,0 @@ -import com.mindee.MindeeClient; -import com.mindee.input.LocalInputSource; -import com.mindee.parsing.common.AsyncPredictResponse; -import com.mindee.product.us.usmail.UsMailV2; -import java.io.File; -import java.io.IOException; - -public class SimpleMindeeClient { - - public static void main(String[] args) throws IOException, InterruptedException { - String apiKey = "my-api-key"; - String filePath = "/path/to/the/file.ext"; - - // Init a new client - MindeeClient mindeeClient = new MindeeClient(apiKey); - - // Load a file from disk - LocalInputSource inputSource = new LocalInputSource(new File(filePath)); - - // Parse the file asynchronously - AsyncPredictResponse response = mindeeClient.enqueueAndParse( - UsMailV2.class, - inputSource - ); - - // Print a summary of the response - System.out.println(response.toString()); - - // Print a summary of the predictions -// System.out.println(response.getDocumentObj().toString()); - - // Print the document-level predictions -// System.out.println(response.getDocumentObj().getInference().getPrediction().toString()); - - // Print the page-level predictions -// response.getDocumentObj().getInference().getPages().forEach( -// page -> System.out.println(page.toString()) -// ); - } - -} diff --git a/src/main/java/com/mindee/product/us/usmail/UsMailV2.java b/src/main/java/com/mindee/product/us/usmail/UsMailV2.java deleted file mode 100644 index daf264a44..000000000 --- a/src/main/java/com/mindee/product/us/usmail/UsMailV2.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.mindee.product.us.usmail; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.mindee.http.EndpointInfo; -import com.mindee.parsing.common.Inference; -import lombok.Getter; - -/** - * US Mail API version 2 inference prediction. - */ -@Getter -@JsonIgnoreProperties(ignoreUnknown = true) -@EndpointInfo(endpointName = "us_mail", version = "2") -public class UsMailV2 - extends Inference { -} diff --git a/src/main/java/com/mindee/product/us/usmail/UsMailV2Document.java b/src/main/java/com/mindee/product/us/usmail/UsMailV2Document.java deleted file mode 100644 index e52458341..000000000 --- a/src/main/java/com/mindee/product/us/usmail/UsMailV2Document.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.mindee.product.us.usmail; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.mindee.parsing.SummaryHelper; -import com.mindee.parsing.common.Prediction; -import com.mindee.parsing.standard.StringField; -import java.util.ArrayList; -import java.util.List; -import lombok.EqualsAndHashCode; -import lombok.Getter; - -/** - * US Mail API version 2.0 document data. - */ -@Getter -@EqualsAndHashCode(callSuper = false) -@JsonIgnoreProperties(ignoreUnknown = true) -public class UsMailV2Document extends Prediction { - - /** - * The addresses of the recipients. - */ - @JsonProperty("recipient_addresses") - protected List recipientAddresses = new ArrayList<>(); - /** - * The names of the recipients. - */ - @JsonProperty("recipient_names") - protected List recipientNames = new ArrayList<>(); - /** - * The address of the sender. - */ - @JsonProperty("sender_address") - protected UsMailV2SenderAddress senderAddress; - /** - * The name of the sender. - */ - @JsonProperty("sender_name") - protected StringField senderName; - - @Override - public boolean isEmpty() { - return ( - this.senderName == null - && this.senderAddress == null - && (this.recipientNames == null || this.recipientNames.isEmpty()) - && (this.recipientAddresses == null || this.recipientAddresses.isEmpty()) - ); - } - - @Override - public String toString() { - StringBuilder outStr = new StringBuilder(); - outStr.append( - String.format(":Sender Name: %s%n", this.getSenderName()) - ); - outStr.append( - String.format(":Sender Address:%n%s", this.getSenderAddress().toFieldList()) - ); - String recipientNames = SummaryHelper.arrayToString( - this.getRecipientNames(), - "%n " - ); - outStr.append( - String.format(":Recipient Names: %s%n", recipientNames) - ); - String recipientAddressesSummary = ""; - if (!this.getRecipientAddresses().isEmpty()) { - int[] recipientAddressesColSizes = new int[]{17, 37, 19, 13, 24, 7, 27}; - recipientAddressesSummary = - String.format("%n%s%n ", SummaryHelper.lineSeparator(recipientAddressesColSizes, "-")) - + "| City " - + "| Complete Address " - + "| Is Address Change " - + "| Postal Code " - + "| Private Mailbox Number " - + "| State " - + "| Street " - + String.format("|%n%s%n ", SummaryHelper.lineSeparator(recipientAddressesColSizes, "=")); - recipientAddressesSummary += SummaryHelper.arrayToString(this.getRecipientAddresses(), recipientAddressesColSizes); - recipientAddressesSummary += String.format("%n%s", SummaryHelper.lineSeparator(recipientAddressesColSizes, "-")); - } - outStr.append( - String.format(":Recipient Addresses: %s%n", recipientAddressesSummary) - ); - return SummaryHelper.cleanSummary(outStr.toString()); - } -} diff --git a/src/main/java/com/mindee/product/us/usmail/UsMailV2RecipientAddress.java b/src/main/java/com/mindee/product/us/usmail/UsMailV2RecipientAddress.java deleted file mode 100644 index 2597f6380..000000000 --- a/src/main/java/com/mindee/product/us/usmail/UsMailV2RecipientAddress.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.mindee.product.us.usmail; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.mindee.parsing.SummaryHelper; -import com.mindee.parsing.standard.BaseField; -import com.mindee.parsing.standard.LineItemField; -import java.util.HashMap; -import java.util.Map; -import lombok.Getter; - -/** - * The addresses of the recipients. - */ -@Getter -@JsonIgnoreProperties(ignoreUnknown = true) -public class UsMailV2RecipientAddress extends BaseField implements LineItemField { - - /** - * The city of the recipient's address. - */ - @JsonProperty("city") - String city; - /** - * The complete address of the recipient. - */ - @JsonProperty("complete") - String complete; - /** - * Indicates if the recipient's address is a change of address. - */ - @JsonProperty("is_address_change") - Boolean isAddressChange; - /** - * The postal code of the recipient's address. - */ - @JsonProperty("postal_code") - String postalCode; - /** - * The private mailbox number of the recipient's address. - */ - @JsonProperty("private_mailbox_number") - String privateMailboxNumber; - /** - * Second part of the ISO 3166-2 code, consisting of two letters indicating the US State. - */ - @JsonProperty("state") - String state; - /** - * The street of the recipient's address. - */ - @JsonProperty("street") - String street; - - public boolean isEmpty() { - return ( - (city == null || city.isEmpty()) - && (complete == null || complete.isEmpty()) - && isAddressChange == null - && (postalCode == null || postalCode.isEmpty()) - && (privateMailboxNumber == null || privateMailboxNumber.isEmpty()) - && (state == null || state.isEmpty()) - && (street == null || street.isEmpty()) - ); - } - - private Map tablePrintableValues() { - Map printable = new HashMap<>(); - - printable.put("city", SummaryHelper.formatForDisplay(this.city, 15)); - printable.put("complete", SummaryHelper.formatForDisplay(this.complete, 35)); - printable.put("isAddressChange", SummaryHelper.formatForDisplay(this.isAddressChange, null)); - printable.put("postalCode", SummaryHelper.formatForDisplay(this.postalCode, null)); - printable.put("privateMailboxNumber", SummaryHelper.formatForDisplay(this.privateMailboxNumber, null)); - printable.put("state", SummaryHelper.formatForDisplay(this.state, null)); - printable.put("street", SummaryHelper.formatForDisplay(this.street, 25)); - return printable; - } - - /** - * Output the line in a format suitable for inclusion in an rST table. - */ - public String toTableLine() { - Map printable = this.tablePrintableValues(); - return String.format("| %-15s ", printable.get("city")) - + String.format("| %-35s ", printable.get("complete")) - + String.format("| %-17s ", printable.get("isAddressChange")) - + String.format("| %-11s ", printable.get("postalCode")) - + String.format("| %-22s ", printable.get("privateMailboxNumber")) - + String.format("| %-5s ", printable.get("state")) - + String.format("| %-25s |", printable.get("street")); - } - - @Override - public String toString() { - Map printable = this.printableValues(); - return String.format("City: %s", printable.get("city")) - + String.format(", Complete Address: %s", printable.get("complete")) - + String.format(", Is Address Change: %s", printable.get("isAddressChange")) - + String.format(", Postal Code: %s", printable.get("postalCode")) - + String.format(", Private Mailbox Number: %s", printable.get("privateMailboxNumber")) - + String.format(", State: %s", printable.get("state")) - + String.format(", Street: %s", printable.get("street")); - } - - private Map printableValues() { - Map printable = new HashMap<>(); - - printable.put("city", SummaryHelper.formatForDisplay(this.city, null)); - printable.put("complete", SummaryHelper.formatForDisplay(this.complete, null)); - printable.put("isAddressChange", SummaryHelper.formatForDisplay(this.isAddressChange, null)); - printable.put("postalCode", SummaryHelper.formatForDisplay(this.postalCode, null)); - printable.put("privateMailboxNumber", SummaryHelper.formatForDisplay(this.privateMailboxNumber, null)); - printable.put("state", SummaryHelper.formatForDisplay(this.state, null)); - printable.put("street", SummaryHelper.formatForDisplay(this.street, null)); - return printable; - } -} diff --git a/src/main/java/com/mindee/product/us/usmail/UsMailV2SenderAddress.java b/src/main/java/com/mindee/product/us/usmail/UsMailV2SenderAddress.java deleted file mode 100644 index 5bb6411c7..000000000 --- a/src/main/java/com/mindee/product/us/usmail/UsMailV2SenderAddress.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.mindee.product.us.usmail; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.mindee.parsing.SummaryHelper; -import com.mindee.parsing.standard.BaseField; -import java.util.HashMap; -import java.util.Map; -import lombok.Getter; - -/** - * The address of the sender. - */ -@Getter -@JsonIgnoreProperties(ignoreUnknown = true) -public class UsMailV2SenderAddress extends BaseField { - - /** - * The city of the sender's address. - */ - @JsonProperty("city") - String city; - /** - * The complete address of the sender. - */ - @JsonProperty("complete") - String complete; - /** - * The postal code of the sender's address. - */ - @JsonProperty("postal_code") - String postalCode; - /** - * Second part of the ISO 3166-2 code, consisting of two letters indicating the US State. - */ - @JsonProperty("state") - String state; - /** - * The street of the sender's address. - */ - @JsonProperty("street") - String street; - - public boolean isEmpty() { - return ( - (city == null || city.isEmpty()) - && (complete == null || complete.isEmpty()) - && (postalCode == null || postalCode.isEmpty()) - && (state == null || state.isEmpty()) - && (street == null || street.isEmpty()) - ); - } - - /** - * Output the object in a format suitable for inclusion in an rST field list. - */ - public String toFieldList() { - Map printable = this.printableValues(); - return String.format(" :City: %s%n", printable.get("city")) - + String.format(" :Complete Address: %s%n", printable.get("complete")) - + String.format(" :Postal Code: %s%n", printable.get("postalCode")) - + String.format(" :State: %s%n", printable.get("state")) - + String.format(" :Street: %s%n", printable.get("street")); - } - - @Override - public String toString() { - Map printable = this.printableValues(); - return String.format("City: %s", printable.get("city")) - + String.format(", Complete Address: %s", printable.get("complete")) - + String.format(", Postal Code: %s", printable.get("postalCode")) - + String.format(", State: %s", printable.get("state")) - + String.format(", Street: %s", printable.get("street")); - } - - private Map printableValues() { - Map printable = new HashMap<>(); - - printable.put("city", SummaryHelper.formatForDisplay(this.city, null)); - printable.put("complete", SummaryHelper.formatForDisplay(this.complete, null)); - printable.put("postalCode", SummaryHelper.formatForDisplay(this.postalCode, null)); - printable.put("state", SummaryHelper.formatForDisplay(this.state, null)); - printable.put("street", SummaryHelper.formatForDisplay(this.street, null)); - return printable; - } -} diff --git a/src/test/java/com/mindee/parsing/v2/InferenceTest.java b/src/test/java/com/mindee/parsing/v2/InferenceTest.java index 0a25123b6..983fe40c2 100644 --- a/src/test/java/com/mindee/parsing/v2/InferenceTest.java +++ b/src/test/java/com/mindee/parsing/v2/InferenceTest.java @@ -464,6 +464,12 @@ void rawTexts_mustBeAccessible() throws IOException { RawText rawText = inference.getResult().getRawText(); assertEquals(2, rawText.getPages().size()); + String documentText = rawText.toString(); + + for (RawTextPage page : rawText.getPages()) { + assertNotNull(page.getContent()); + assertFalse(page.getContent().isEmpty()); + } RawTextPage first = rawText.getPages().get(0); assertEquals("This is the raw text of the first page...", first.getContent()); diff --git a/src/test/java/com/mindee/product/us/usmail/UsMailV2Test.java b/src/test/java/com/mindee/product/us/usmail/UsMailV2Test.java deleted file mode 100644 index aacf7709c..000000000 --- a/src/test/java/com/mindee/product/us/usmail/UsMailV2Test.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.mindee.product.us.usmail; - -import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.mindee.parsing.common.Document; -import com.mindee.parsing.common.PredictResponse; -import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import java.io.File; -import java.io.IOException; - -/** - * Unit tests for UsMailV2. - */ -public class UsMailV2Test { - - protected PredictResponse getPrediction(String name) throws IOException { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.findAndRegisterModules(); - - JavaType type = objectMapper.getTypeFactory().constructParametricType( - PredictResponse.class, - UsMailV2.class - ); - return objectMapper.readValue( - new File("src/test/resources/products/us_mail/response_v2/" + name + ".json"), - type - ); - } - - @Test - void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { - PredictResponse response = getPrediction("empty"); - UsMailV2Document docPrediction = response.getDocument().getInference().getPrediction(); - Assertions.assertNull(docPrediction.getSenderName().getValue()); - Assertions.assertNull(docPrediction.getSenderAddress().getCity()); - Assertions.assertNull(docPrediction.getSenderAddress().getComplete()); - Assertions.assertNull(docPrediction.getSenderAddress().getPostalCode()); - Assertions.assertNull(docPrediction.getSenderAddress().getState()); - Assertions.assertNull(docPrediction.getSenderAddress().getStreet()); - Assertions.assertTrue(docPrediction.getRecipientNames().isEmpty()); - Assertions.assertTrue(docPrediction.getRecipientAddresses().isEmpty()); - } - - @Test - void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { - PredictResponse response = getPrediction("complete"); - Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( - doc.toString(), - "src/test/resources/products/us_mail/response_v2/summary_full.rst" - ); - } - -}