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
41 changes: 41 additions & 0 deletions docs/code_samples/us_driver_license_v1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import com.mindee.MindeeClient;
import com.mindee.input.LocalInputSource;
import com.mindee.parsing.common.PredictResponse;
import com.mindee.product.us.driverlicense.DriverLicenseV1;
import java.io.File;
import java.io.IOException;

public class SimpleMindeeClient {

public static void main(String[] args) throws IOException {
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
PredictResponse<DriverLicenseV1> response = mindeeClient.parse(
DriverLicenseV1.class,
inputSource
);

// Print a summary of the response
System.out.println(response.toString());

// Print a summary of the predictions
// System.out.println(response.getDocument().toString());

// Print the document-level predictions
// System.out.println(response.getDocument().getInference().getPrediction().toString());

// Print the page-level predictions
// response.getDocument().getInference().getPages().forEach(
// page -> System.out.println(page.toString())
// );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.mindee.product.us.driverlicense;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.mindee.http.EndpointInfo;
import com.mindee.parsing.common.Inference;
import lombok.Getter;

/**
* The definition for Driver License, API version 1.
*/
@Getter
@JsonIgnoreProperties(ignoreUnknown = true)
@EndpointInfo(endpointName = "us_driver_license", version = "1")
public class DriverLicenseV1
extends Inference<DriverLicenseV1Page, DriverLicenseV1Document> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package com.mindee.product.us.driverlicense;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.mindee.parsing.SummaryHelper;
import com.mindee.parsing.standard.DateField;
import com.mindee.parsing.standard.StringField;
import lombok.EqualsAndHashCode;
import lombok.Getter;

/**
* Document data for Driver License, API version 1.
*/
@Getter
@EqualsAndHashCode
@JsonIgnoreProperties(ignoreUnknown = true)
public class DriverLicenseV1Document {

/**
* US driver license holders address
*/
@JsonProperty("address")
private StringField address;
/**
* US driver license holders date of birth
*/
@JsonProperty("date_of_birth")
private DateField dateOfBirth;
/**
* Document Discriminator Number of the US Driver License
*/
@JsonProperty("dd_number")
private StringField ddNumber;
/**
* US driver license holders class
*/
@JsonProperty("dl_class")
private StringField dlClass;
/**
* ID number of the US Driver License.
*/
@JsonProperty("driver_license_id")
private StringField driverLicenseId;
/**
* US driver license holders endorsements
*/
@JsonProperty("endorsements")
private StringField endorsements;
/**
* Date on which the documents expires.
*/
@JsonProperty("expiry_date")
private DateField expiryDate;
/**
* US driver license holders eye colour
*/
@JsonProperty("eye_color")
private StringField eyeColor;
/**
* US driver license holders first name(s)
*/
@JsonProperty("first_name")
private StringField firstName;
/**
* US driver license holders hair colour
*/
@JsonProperty("hair_color")
private StringField hairColor;
/**
* US driver license holders hight
*/
@JsonProperty("height")
private StringField height;
/**
* Date on which the documents was issued.
*/
@JsonProperty("issued_date")
private DateField issuedDate;
/**
* US driver license holders last name
*/
@JsonProperty("last_name")
private StringField lastName;
/**
* US driver license holders restrictions
*/
@JsonProperty("restrictions")
private StringField restrictions;
/**
* US driver license holders gender
*/
@JsonProperty("sex")
private StringField sex;
/**
* US State
*/
@JsonProperty("state")
private StringField state;
/**
* US driver license holders weight
*/
@JsonProperty("weight")
private StringField weight;

@Override
public String toString() {
StringBuilder outStr = new StringBuilder();
outStr.append(
String.format(":State: %s%n", this.getState())
);
outStr.append(
String.format(":Driver License ID: %s%n", this.getDriverLicenseId())
);
outStr.append(
String.format(":Expiry Date: %s%n", this.getExpiryDate())
);
outStr.append(
String.format(":Date Of Issue: %s%n", this.getIssuedDate())
);
outStr.append(
String.format(":Last Name: %s%n", this.getLastName())
);
outStr.append(
String.format(":First Name: %s%n", this.getFirstName())
);
outStr.append(
String.format(":Address: %s%n", this.getAddress())
);
outStr.append(
String.format(":Date Of Birth: %s%n", this.getDateOfBirth())
);
outStr.append(
String.format(":Restrictions: %s%n", this.getRestrictions())
);
outStr.append(
String.format(":Endorsements: %s%n", this.getEndorsements())
);
outStr.append(
String.format(":Driver License Class: %s%n", this.getDlClass())
);
outStr.append(
String.format(":Sex: %s%n", this.getSex())
);
outStr.append(
String.format(":Height: %s%n", this.getHeight())
);
outStr.append(
String.format(":Weight: %s%n", this.getWeight())
);
outStr.append(
String.format(":Hair Color: %s%n", this.getHairColor())
);
outStr.append(
String.format(":Eye Color: %s%n", this.getEyeColor())
);
outStr.append(
String.format(":Document Discriminator: %s%n", this.getDdNumber())
);
return SummaryHelper.cleanSummary(outStr.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.mindee.product.us.driverlicense;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.mindee.parsing.SummaryHelper;
import com.mindee.parsing.standard.PositionField;
import lombok.EqualsAndHashCode;
import lombok.Getter;

/**
* Page data for Driver License, API version 1.
*/
@Getter
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DriverLicenseV1Page extends DriverLicenseV1Document {

/**
* Has a photo of the US driver license holder
*/
@JsonProperty("photo")
private PositionField photo;
/**
* Has a signature of the US driver license holder
*/
@JsonProperty("signature")
private PositionField signature;

@Override
public String toString() {
StringBuilder outStr = new StringBuilder();
outStr.append(
String.format(":Photo: %s%n", this.getPhoto())
);
outStr.append(
String.format(":Signature: %s%n", this.getSignature())
);
outStr.append(super.toString());
return SummaryHelper.cleanSummary(outStr.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.mindee.product.us.driverlicense;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mindee.parsing.common.Document;
import com.mindee.parsing.common.Page;
import com.mindee.parsing.common.PredictResponse;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

/**
* Unit tests for DriverLicenseV1.
*/
public class DriverLicenseV1Test {

protected PredictResponse<DriverLicenseV1> getPrediction() throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.findAndRegisterModules();

JavaType type = objectMapper.getTypeFactory().constructParametricType(
PredictResponse.class,
DriverLicenseV1.class
);
return objectMapper.readValue(
new File("src/test/resources/us/driver_license/response_v1/complete.json"),
type
);
}

@Test
void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException {
PredictResponse<DriverLicenseV1> prediction = getPrediction();
Document<DriverLicenseV1> doc = prediction.getDocument();
String[] actualLines = doc.toString().split(System.lineSeparator());
List<String> expectedLines = Files.readAllLines(
Paths.get("src/test/resources/us/driver_license/response_v1/summary_full.rst")
);
String expectedSummary = String.join(String.format("%n"), expectedLines);
String actualSummary = String.join(String.format("%n"), actualLines);

Assertions.assertEquals(expectedSummary, actualSummary);
}

@Test
void whenCompleteDeserialized_mustHaveValidPage0Summary() throws IOException {
PredictResponse<DriverLicenseV1> prediction = getPrediction();
Page<DriverLicenseV1Page> page = prediction.getDocument().getInference().getPages().get(0);
String[] actualLines = page.toString().split(System.lineSeparator());
List<String> expectedLines = Files.readAllLines(
Paths.get("src/test/resources/us/driver_license/response_v1/summary_page0.rst")
);
String expectedSummary = String.join(String.format("%n"), expectedLines);
String actualSummary = String.join(String.format("%n"), actualLines);

Assertions.assertEquals(expectedSummary, actualSummary);
}
}