Custom OCR Java
The JAVA OCR SDK supports custom-built API from the API Builder.
If your document isn't covered by one of Mindee's Off-the-Shelf APIs,
you can create your own API using the API Builder.
For the following examples, we are using our own W9s custom API
created with the API Builder.
Quick Start
String path = "/path/to/the/file.ext";
DocumentToParse documentToParse = new DocumentToParse(new File(path));
CustomEndpoint myEndpoint = new CustomEndpoint(
"wnine",
"john",
"1.0" // optional
);
Document<CustomV1Inference> customDocument = mindeeClient
.parse(documentToParse, myEndpoint);
If the version
argument is set, you'll be required to update it every time a new model is trained.
This is probably not needed for development but essential for production use.
Parsing Documents
Use the ParseAsync
method to call the API prediction on your custom document.
The response class and document type must be specified when calling this method.
You have two different ways to parse a custom document.
- Use the default one (named
CustomPrediction
):
String path = "/path/to/the/file.ext";
DocumentToParse documentToParse = new DocumentToParse(new File(path));
CustomEndpoint myEndpoint = new CustomEndpoint(
"wnine",
"john",
"1.0" // optional
);
Document<CustomV1Inference> customDocument = mindeeClient.parse(documentToParse, myEndpoint);
- You can also use your own class which will represent the required fields. For example:
// The CustomEndpointInfo annotation is required when using your own model.
// It will be used to know which Mindee API to call.
public class WNineV1DocumentPrediction {
@JsonProperty("name")
private StringField name;
@JsonProperty("employerId")
private StringField employerId;
(...)
}
@EndpointInfo(endpointName = "wnine", accountName = "john" version = "1")
public class WNineV1Inference
extends Inference Inference<WNineV1DocumentPrediction, WNineV1DocumentPrediction> {
}
String path = "/path/to/the/file.ext";
DocumentToParse documentToParse = new DocumentToParse(new File(path));
Document<WNineV1Inference> myCustomDocument = mindeeClient
.parse(WNineV1Inference.class, documentToParse);
CustomV1Inference object
All the fields which are present in the API builder
are available (the fields are defined when creating your custom API).
CustomV1Inference
is an object which contains a document prediction and pages prediction result.
CustomV1PagePrediction
CustomV1PagePrediction
Which is a HashMap<String, ListField>
with the key as a string
for the name of the field, and a ListField
as a value.
CustomV1DocumentPrediction
CustomV1DocumentPrediction
Which contains 2 properties : classificationFields
and fields
.
Both are a Map and the key is a string
for the name of the field and for the value :
classificationFields
have aClassificationField
object as value. EachClassificationField
contains a value.fields
have aListField
object as value. EachListField
contains a list of all values extracted for this field.
Info
Both document level and page level objects work in the same way.
Fields property
A Map with the following structure:
confidence
: adouble
values
: a list ofListFieldValue
which containing a list of all values found for the field.
In the examples below we'll use the employer_id
field.
String path = "/path/to/the/file.ext";
DocumentToParse documentToParse = new DocumentToParse(new File(path));
Document<WNineV1Inference> myCustomDocument = mindeeClient
.parse(WNineV1Inference.class, documentToParse);
ListField employerId = document.getInference().getDocumentPrediction().get("employer_id");
Questions?
Updated 2 months ago