Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/mindee/v2/product/crop/CropItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/mindee/v2/product/split/SplitRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
35 changes: 32 additions & 3 deletions src/test/java/com/mindee/v2/product/ClassificationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
);
}
}
}
10 changes: 5 additions & 5 deletions src/test/java/com/mindee/v2/product/CropIT.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -54,15 +54,15 @@ 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());
assertEquals(modelId, inference.getModel().getId());

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());
}
}
69 changes: 56 additions & 13 deletions src/test/java/com/mindee/v2/product/CropTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,18 +26,18 @@ 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());

ArrayList<CropItem> 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
Expand All @@ -54,23 +55,23 @@ 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());

ArrayList<CropItem> 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
Expand All @@ -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<CropItem> 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()
);
}
}
}
68 changes: 55 additions & 13 deletions src/test/java/com/mindee/v2/product/SplitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,41 +25,82 @@ 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<SplitRange> 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));
}
}

@Nested
@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());

ArrayList<SplitRange> 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<SplitRange> 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()
);
}
}
}
Loading