Skip to content

Commit 6f8b33b

Browse files
committed
add classification classes
1 parent 981e2df commit 6f8b33b

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.mindee.v2.product.classification;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import lombok.Getter;
6+
7+
/**
8+
* Classification of the document type from the source file.
9+
*/
10+
@Getter
11+
@JsonIgnoreProperties(ignoreUnknown = true)
12+
public class ClassificationClassifier {
13+
/**
14+
* The document type, as identified on given classification values.
15+
*/
16+
@JsonProperty("document_type")
17+
private String documentType;
18+
19+
@Override
20+
public String toString() {
21+
return "Document Type: " + documentType;
22+
}
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.mindee.v2.product.classification;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.mindee.v2.parsing.BaseInference;
6+
import lombok.Getter;
7+
8+
/**
9+
* The inference result for a classification utility request.
10+
*/
11+
@Getter
12+
@JsonIgnoreProperties(ignoreUnknown = true)
13+
public class ClassificationInference extends BaseInference {
14+
/**
15+
* Result of the document classifier inference.
16+
*/
17+
@JsonProperty("result")
18+
private ClassificationResult result;
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.mindee.v2.product.classification;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.mindee.parsing.v2.CommonResponse;
6+
import lombok.Getter;
7+
8+
/**
9+
* Response for a classification utility inference.
10+
*/
11+
@Getter
12+
@JsonIgnoreProperties(ignoreUnknown = true)
13+
public class ClassificationResponse extends CommonResponse {
14+
15+
/**
16+
* The inference result for a classification utility request.
17+
*/
18+
@JsonProperty("inference")
19+
private ClassificationInference inference;
20+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.mindee.v2.product.classification;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import java.util.StringJoiner;
6+
import lombok.AllArgsConstructor;
7+
import lombok.EqualsAndHashCode;
8+
import lombok.Getter;
9+
import lombok.NoArgsConstructor;
10+
11+
/**
12+
* Result of the document classifier inference.
13+
*/
14+
@Getter
15+
@EqualsAndHashCode
16+
@JsonIgnoreProperties(ignoreUnknown = true)
17+
@AllArgsConstructor
18+
@NoArgsConstructor
19+
public final class ClassificationResult {
20+
/**
21+
* Classification of the document type from the source file.
22+
*/
23+
@JsonProperty("classification")
24+
private ClassificationClassifier classification;
25+
26+
@Override
27+
public String toString() {
28+
StringJoiner joiner = new StringJoiner("\n");
29+
joiner.add("Classification").add("==============");
30+
joiner.add(classification.toString());
31+
32+
return joiner.toString();
33+
}
34+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.mindee.v2.product;
2+
3+
import static com.mindee.TestingUtilities.getV2ResourcePath;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertNotNull;
6+
7+
import com.mindee.input.LocalResponse;
8+
import com.mindee.v2.product.classification.ClassificationResponse;
9+
import java.io.IOException;
10+
import org.junit.jupiter.api.DisplayName;
11+
import org.junit.jupiter.api.Nested;
12+
import org.junit.jupiter.api.Test;
13+
14+
@DisplayName("MindeeV2 - Classification Model Tests")
15+
public class ClassificationTest {
16+
private ClassificationResponse loadResponse(String filePath) throws IOException {
17+
LocalResponse localResponse = new LocalResponse(getV2ResourcePath(filePath));
18+
return localResponse.deserializeResponse(ClassificationResponse.class);
19+
}
20+
21+
@Nested
22+
@DisplayName("Classification with single value")
23+
class SinglePredictionTest {
24+
@Test
25+
@DisplayName("all properties must be valid")
26+
void whenSingle_mustHaveValidProperties() throws IOException {
27+
ClassificationResponse response = loadResponse(
28+
"products/classification/classification_single.json"
29+
);
30+
assertNotNull(response.getInference());
31+
assertEquals(
32+
"invoice",
33+
response.getInference().getResult().getClassification().getDocumentType()
34+
);
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)