diff --git a/src/main/java/com/mindee/v2/product/classification/ClassificationClassifier.java b/src/main/java/com/mindee/v2/product/classification/ClassificationClassifier.java index ac9292210..cee1ae606 100644 --- a/src/main/java/com/mindee/v2/product/classification/ClassificationClassifier.java +++ b/src/main/java/com/mindee/v2/product/classification/ClassificationClassifier.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.v2.InferenceResponse; import lombok.Getter; /** @@ -16,6 +17,12 @@ public class ClassificationClassifier { @JsonProperty("document_type") private String documentType; + /** + * The extraction response associated with the classification. + */ + @JsonProperty("extraction_response") + private InferenceResponse extractionResponse; + @Override public String toString() { return "Document Type: " + documentType; diff --git a/src/main/java/com/mindee/v2/product/crop/CropItem.java b/src/main/java/com/mindee/v2/product/crop/CropItem.java index 1c8c1aa1c..01389e9b2 100644 --- a/src/main/java/com/mindee/v2/product/crop/CropItem.java +++ b/src/main/java/com/mindee/v2/product/crop/CropItem.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.v2.InferenceResponse; import com.mindee.parsing.v2.field.FieldLocation; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; @@ -29,6 +30,12 @@ public class CropItem { @JsonProperty("location") private FieldLocation location; + /** + * The extraction response associated with the crop. + */ + @JsonProperty("extraction_response") + private InferenceResponse extractionResponse; + @Override public String toString() { return "* :Location: " + location + "\n :Object Type: " + objectType; diff --git a/src/main/java/com/mindee/v2/product/split/SplitRange.java b/src/main/java/com/mindee/v2/product/split/SplitRange.java index 254805204..0e1ee714e 100644 --- a/src/main/java/com/mindee/v2/product/split/SplitRange.java +++ b/src/main/java/com/mindee/v2/product/split/SplitRange.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.v2.InferenceResponse; import java.util.ArrayList; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; @@ -29,4 +30,10 @@ public class SplitRange { */ @JsonProperty("document_type") public String documentType; + + /** + * The extraction response associated with the split. + */ + @JsonProperty("extraction_response") + private InferenceResponse extractionResponse; } diff --git a/src/test/java/com/mindee/v2/product/ClassificationTest.java b/src/test/java/com/mindee/v2/product/ClassificationTest.java index d73f029bb..e734f4a3a 100644 --- a/src/test/java/com/mindee/v2/product/ClassificationTest.java +++ b/src/test/java/com/mindee/v2/product/ClassificationTest.java @@ -3,8 +3,10 @@ import static com.mindee.TestingUtilities.getV2ResourcePath; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import com.mindee.input.LocalResponse; +import com.mindee.parsing.v2.InferenceResponse; import com.mindee.v2.product.classification.ClassificationResponse; import java.io.IOException; import org.junit.jupiter.api.DisplayName; @@ -22,16 +24,43 @@ private ClassificationResponse loadResponse(String filePath) throws IOException @DisplayName("Result with single value") class SinglePredictionTest { @Test - @DisplayName("all properties must be valid") - void mustHaveValidProperties() throws IOException { + @DisplayName("classification properties must be valid") + void singleMustHaveValidProperties() throws IOException { + ClassificationResponse response = loadResponse("products/classification/default_sample.json"); + assertNotNull(response.getInference()); + assertEquals( + "invoice", + response.getInference().getResult().getClassification().getDocumentType() + ); + assertNull(response.getInference().getResult().getClassification().getExtractionResponse()); + } + + @Test + @DisplayName("extraction properties must be valid") + void singleExtractionMustHaveValidProperties() throws IOException { ClassificationResponse response = loadResponse( - "products/classification/classification_single.json" + "products/classification/default_sample_extraction.json" ); assertNotNull(response.getInference()); assertEquals( "invoice", response.getInference().getResult().getClassification().getDocumentType() ); + InferenceResponse extractionResponse = response + .getInference() + .getResult() + .getClassification() + .getExtractionResponse(); + assertNotNull(extractionResponse); + assertEquals( + "Jiro Doi", + extractionResponse + .getInference() + .getResult() + .getFields() + .getSimpleField("customer_name") + .getStringValue() + ); } } } diff --git a/src/test/java/com/mindee/v2/product/CropIT.java b/src/test/java/com/mindee/v2/product/CropIT.java index f4d445967..8a598be0f 100644 --- a/src/test/java/com/mindee/v2/product/CropIT.java +++ b/src/test/java/com/mindee/v2/product/CropIT.java @@ -1,6 +1,6 @@ package com.mindee.v2.product; -import static com.mindee.TestingUtilities.getResourcePath; +import static com.mindee.TestingUtilities.getV2ResourcePath; import static org.junit.jupiter.api.Assertions.*; import com.mindee.AsyncPollingOptions; @@ -37,7 +37,7 @@ void setUp() { @DisplayName("Empty, multi-page PDF – enqueue & parse must succeed") void parseFile_emptyMultiPage_mustSucceed() throws IOException, InterruptedException { LocalInputSource source = new LocalInputSource( - getResourcePath("file_types/pdf/multipage_cut-2.pdf") + getV2ResourcePath("products/crop/multipage_sample.pdf") ); CropParameters params = CropParameters .builder(modelId) @@ -54,7 +54,7 @@ void parseFile_emptyMultiPage_mustSucceed() throws IOException, InterruptedExcep InferenceFile file = inference.getFile(); assertNotNull(file); - assertEquals("multipage_cut-2.pdf", file.getName()); + assertEquals("multipage_sample.pdf", file.getName()); assertEquals(2, file.getPageCount()); assertNotNull(inference.getModel()); @@ -62,7 +62,7 @@ void parseFile_emptyMultiPage_mustSucceed() throws IOException, InterruptedExcep CropResult result = inference.getResult(); assertNotNull(result); - assertEquals(1, result.getCrops().size()); - assertEquals("other", result.getCrops().get(0).getObjectType()); + assertEquals(5, result.getCrops().size()); + assertEquals("receipt", result.getCrops().get(0).getObjectType()); } } diff --git a/src/test/java/com/mindee/v2/product/CropTest.java b/src/test/java/com/mindee/v2/product/CropTest.java index f0df46732..f01e6f06d 100644 --- a/src/test/java/com/mindee/v2/product/CropTest.java +++ b/src/test/java/com/mindee/v2/product/CropTest.java @@ -6,6 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import com.mindee.input.LocalResponse; +import com.mindee.parsing.v2.InferenceResponse; import com.mindee.v2.product.crop.CropItem; import com.mindee.v2.product.crop.CropResponse; import java.io.IOException; @@ -25,7 +26,7 @@ private CropResponse loadResponse(String filePath) throws IOException { @DisplayName("Result with single value") class SinglePredictionTest { @Test - @DisplayName("all properties must be valid") + @DisplayName("crop properties must be valid") void mustHaveValidProperties() throws IOException { CropResponse response = loadResponse("products/crop/crop_single.json"); assertNotNull(response.getInference()); @@ -33,10 +34,10 @@ void mustHaveValidProperties() throws IOException { ArrayList crops = response.getInference().getResult().getCrops(); assertEquals(1, crops.size()); - CropItem crop1 = crops.get(0); - assertEquals("invoice", crop1.getObjectType()); - assertNotNull(crop1.getLocation().getPolygon()); - assertEquals(0, crop1.getLocation().getPage()); + CropItem crop0 = crops.get(0); + assertEquals("invoice", crop0.getObjectType()); + assertNotNull(crop0.getLocation().getPolygon()); + assertEquals(0, crop0.getLocation().getPage()); } @Test @@ -54,7 +55,7 @@ void mustHaveValidDisplay() throws IOException { @DisplayName("Result with multiple values") class MultiPredictionTest { @Test - @DisplayName("all properties must be valid") + @DisplayName("crop properties must be valid") void mustHaveValidProperties() throws IOException { CropResponse response = loadResponse("products/crop/crop_multiple.json"); assertNotNull(response.getInference()); @@ -62,15 +63,15 @@ void mustHaveValidProperties() throws IOException { ArrayList crops = response.getInference().getResult().getCrops(); assertEquals(2, crops.size()); - CropItem crop1 = crops.get(0); - assertEquals("invoice", crop1.getObjectType()); + CropItem crop0 = crops.get(0); + assertEquals("invoice", crop0.getObjectType()); + assertNotNull(crop0.getLocation().getPolygon()); + assertEquals(0, crop0.getLocation().getPage()); + + CropItem crop1 = crops.get(1); + assertEquals("receipt", crop1.getObjectType()); assertNotNull(crop1.getLocation().getPolygon()); assertEquals(0, crop1.getLocation().getPage()); - - CropItem crop2 = crops.get(1); - assertEquals("receipt", crop2.getObjectType()); - assertNotNull(crop2.getLocation().getPolygon()); - assertEquals(0, crop2.getLocation().getPage()); } @Test @@ -82,5 +83,47 @@ void mustHaveValidDisplay() throws IOException { getV2ResourcePath("products/crop/crop_multiple.rst") ); } + + @Test + @DisplayName("extraction properties must be valid") + void extractionMustHaveValidProperties() throws IOException { + CropResponse response = loadResponse("products/crop/default_sample_extraction.json"); + assertNotNull(response.getInference()); + + ArrayList crops = response.getInference().getResult().getCrops(); + assertEquals(2, crops.size()); + + CropItem crop0 = crops.get(0); + assertEquals("receipt", crop0.getObjectType()); + assertNotNull(crop0.getLocation().getPolygon()); + assertEquals(0, crop0.getLocation().getPage()); + InferenceResponse extractionResponse0 = crop0.getExtractionResponse(); + assertNotNull(extractionResponse0); + assertEquals( + "CHEZ ALAIN MIAM MIAM", + extractionResponse0 + .getInference() + .getResult() + .getFields() + .getSimpleField("supplier_name") + .getValue() + ); + + CropItem crop1 = crops.get(1); + assertEquals("receipt", crop1.getObjectType()); + assertNotNull(crop1.getLocation().getPolygon()); + assertEquals(0, crop1.getLocation().getPage()); + InferenceResponse extractionResponse1 = crop1.getExtractionResponse(); + assertNotNull(extractionResponse1); + assertEquals( + "La cerise sur la pizza", + extractionResponse1 + .getInference() + .getResult() + .getFields() + .getSimpleField("supplier_name") + .getValue() + ); + } } } diff --git a/src/test/java/com/mindee/v2/product/SplitTest.java b/src/test/java/com/mindee/v2/product/SplitTest.java index 08a21bef8..480a5c35d 100644 --- a/src/test/java/com/mindee/v2/product/SplitTest.java +++ b/src/test/java/com/mindee/v2/product/SplitTest.java @@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import com.mindee.input.LocalResponse; +import com.mindee.parsing.v2.InferenceResponse; import com.mindee.v2.product.split.SplitRange; import com.mindee.v2.product.split.SplitResponse; import java.io.IOException; @@ -24,15 +25,16 @@ private SplitResponse loadResponse(String filePath) throws IOException { @DisplayName("Result with single value") class SinglePredictionTest { @Test - @DisplayName("all properties must be valid") + @DisplayName("split properties must be valid") void mustHaveValidProperties() throws IOException { SplitResponse response = loadResponse("products/split/split_single.json"); assertNotNull(response.getInference()); ArrayList splits = response.getInference().getResult().getSplits(); assertEquals(1, splits.size()); - assertEquals("receipt", splits.get(0).getDocumentType()); - assertEquals(0, splits.get(0).getPageRange().get(0)); + SplitRange split0 = splits.get(0); + assertEquals("receipt", split0.getDocumentType()); + assertEquals(0, split0.getPageRange().get(0)); } } @@ -40,7 +42,7 @@ void mustHaveValidProperties() throws IOException { @DisplayName("Result with multiple values") class MultiPredictionTest { @Test - @DisplayName("all properties must be valid") + @DisplayName("split properties must be valid") void mustHaveValidProperties() throws IOException { SplitResponse response = loadResponse("products/split/split_multiple.json"); assertNotNull(response.getInference()); @@ -48,17 +50,57 @@ void mustHaveValidProperties() throws IOException { ArrayList splits = response.getInference().getResult().getSplits(); assertEquals(3, splits.size()); - SplitRange split1 = splits.get(0); - assertEquals("passport", split1.getDocumentType()); - assertEquals(0, split1.getPageRange().get(0)); + SplitRange split0 = splits.get(0); + assertEquals("passport", split0.getDocumentType()); + assertEquals(0, split0.getPageRange().get(0)); - SplitRange split2 = splits.get(1); - assertEquals("invoice", split2.getDocumentType()); - assertEquals(1, split2.getPageRange().get(0)); + SplitRange split1 = splits.get(1); + assertEquals("invoice", split1.getDocumentType()); + assertEquals(1, split1.getPageRange().get(0)); - SplitRange split3 = splits.get(2); - assertEquals("receipt", split3.getDocumentType()); - assertEquals(4, split3.getPageRange().get(0)); + SplitRange split2 = splits.get(2); + assertEquals("receipt", split2.getDocumentType()); + assertEquals(4, split2.getPageRange().get(0)); + } + + @Test + @DisplayName("extraction properties must be valid") + void extractionMustHaveValidProperties() throws IOException { + SplitResponse response = loadResponse("products/split/default_sample_extraction.json"); + assertNotNull(response.getInference()); + + ArrayList splits = response.getInference().getResult().getSplits(); + assertEquals(2, splits.size()); + + SplitRange split0 = splits.get(0); + assertEquals("invoice", split0.getDocumentType()); + assertEquals(0, split0.getPageRange().get(0)); + InferenceResponse extractionResponse0 = split0.getExtractionResponse(); + assertNotNull(extractionResponse0); + assertEquals( + "05 05 44 44 90", + extractionResponse0 + .getInference() + .getResult() + .getFields() + .getSimpleField("supplier_phone_number") + .getValue() + ); + + SplitRange split1 = splits.get(1); + assertEquals("invoice", split1.getDocumentType()); + assertEquals(1, split1.getPageRange().get(0)); + InferenceResponse extractionResponse1 = split1.getExtractionResponse(); + assertNotNull(extractionResponse1); + assertEquals( + "416-555-1212", + extractionResponse1 + .getInference() + .getResult() + .getFields() + .getSimpleField("supplier_phone_number") + .getValue() + ); } } } diff --git a/src/test/resources b/src/test/resources index 53f0efbc0..315efcc30 160000 --- a/src/test/resources +++ b/src/test/resources @@ -1 +1 @@ -Subproject commit 53f0efbc08c77c2c085aadd27de9d2d6c359276e +Subproject commit 315efcc302efacfb75a6b101788058658e8c37e4