Skip to content

Commit bdf4402

Browse files
authored
✨ add support for US driver license v1 (#111)
1 parent 67480f7 commit bdf4402

File tree

6 files changed

+322
-1
lines changed

6 files changed

+322
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import com.mindee.MindeeClient;
2+
import com.mindee.input.LocalInputSource;
3+
import com.mindee.parsing.common.PredictResponse;
4+
import com.mindee.product.us.driverlicense.DriverLicenseV1;
5+
import java.io.File;
6+
import java.io.IOException;
7+
8+
public class SimpleMindeeClient {
9+
10+
public static void main(String[] args) throws IOException {
11+
String apiKey = "my-api-key";
12+
String filePath = "/path/to/the/file.ext";
13+
14+
// Init a new client
15+
MindeeClient mindeeClient = new MindeeClient(apiKey);
16+
17+
// Load a file from disk
18+
LocalInputSource inputSource = new LocalInputSource(new File(filePath));
19+
20+
// Parse the file
21+
PredictResponse<DriverLicenseV1> response = mindeeClient.parse(
22+
DriverLicenseV1.class,
23+
inputSource
24+
);
25+
26+
// Print a summary of the response
27+
System.out.println(response.toString());
28+
29+
// Print a summary of the predictions
30+
// System.out.println(response.getDocument().toString());
31+
32+
// Print the document-level predictions
33+
// System.out.println(response.getDocument().getInference().getPrediction().toString());
34+
35+
// Print the page-level predictions
36+
// response.getDocument().getInference().getPages().forEach(
37+
// page -> System.out.println(page.toString())
38+
// );
39+
}
40+
41+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.mindee.product.us.driverlicense;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.mindee.http.EndpointInfo;
5+
import com.mindee.parsing.common.Inference;
6+
import lombok.Getter;
7+
8+
/**
9+
* The definition for Driver License, API version 1.
10+
*/
11+
@Getter
12+
@JsonIgnoreProperties(ignoreUnknown = true)
13+
@EndpointInfo(endpointName = "us_driver_license", version = "1")
14+
public class DriverLicenseV1
15+
extends Inference<DriverLicenseV1Page, DriverLicenseV1Document> {
16+
}
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
package com.mindee.product.us.driverlicense;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.mindee.parsing.SummaryHelper;
6+
import com.mindee.parsing.standard.DateField;
7+
import com.mindee.parsing.standard.StringField;
8+
import lombok.EqualsAndHashCode;
9+
import lombok.Getter;
10+
11+
/**
12+
* Document data for Driver License, API version 1.
13+
*/
14+
@Getter
15+
@EqualsAndHashCode
16+
@JsonIgnoreProperties(ignoreUnknown = true)
17+
public class DriverLicenseV1Document {
18+
19+
/**
20+
* US driver license holders address
21+
*/
22+
@JsonProperty("address")
23+
private StringField address;
24+
/**
25+
* US driver license holders date of birth
26+
*/
27+
@JsonProperty("date_of_birth")
28+
private DateField dateOfBirth;
29+
/**
30+
* Document Discriminator Number of the US Driver License
31+
*/
32+
@JsonProperty("dd_number")
33+
private StringField ddNumber;
34+
/**
35+
* US driver license holders class
36+
*/
37+
@JsonProperty("dl_class")
38+
private StringField dlClass;
39+
/**
40+
* ID number of the US Driver License.
41+
*/
42+
@JsonProperty("driver_license_id")
43+
private StringField driverLicenseId;
44+
/**
45+
* US driver license holders endorsements
46+
*/
47+
@JsonProperty("endorsements")
48+
private StringField endorsements;
49+
/**
50+
* Date on which the documents expires.
51+
*/
52+
@JsonProperty("expiry_date")
53+
private DateField expiryDate;
54+
/**
55+
* US driver license holders eye colour
56+
*/
57+
@JsonProperty("eye_color")
58+
private StringField eyeColor;
59+
/**
60+
* US driver license holders first name(s)
61+
*/
62+
@JsonProperty("first_name")
63+
private StringField firstName;
64+
/**
65+
* US driver license holders hair colour
66+
*/
67+
@JsonProperty("hair_color")
68+
private StringField hairColor;
69+
/**
70+
* US driver license holders hight
71+
*/
72+
@JsonProperty("height")
73+
private StringField height;
74+
/**
75+
* Date on which the documents was issued.
76+
*/
77+
@JsonProperty("issued_date")
78+
private DateField issuedDate;
79+
/**
80+
* US driver license holders last name
81+
*/
82+
@JsonProperty("last_name")
83+
private StringField lastName;
84+
/**
85+
* US driver license holders restrictions
86+
*/
87+
@JsonProperty("restrictions")
88+
private StringField restrictions;
89+
/**
90+
* US driver license holders gender
91+
*/
92+
@JsonProperty("sex")
93+
private StringField sex;
94+
/**
95+
* US State
96+
*/
97+
@JsonProperty("state")
98+
private StringField state;
99+
/**
100+
* US driver license holders weight
101+
*/
102+
@JsonProperty("weight")
103+
private StringField weight;
104+
105+
@Override
106+
public String toString() {
107+
StringBuilder outStr = new StringBuilder();
108+
outStr.append(
109+
String.format(":State: %s%n", this.getState())
110+
);
111+
outStr.append(
112+
String.format(":Driver License ID: %s%n", this.getDriverLicenseId())
113+
);
114+
outStr.append(
115+
String.format(":Expiry Date: %s%n", this.getExpiryDate())
116+
);
117+
outStr.append(
118+
String.format(":Date Of Issue: %s%n", this.getIssuedDate())
119+
);
120+
outStr.append(
121+
String.format(":Last Name: %s%n", this.getLastName())
122+
);
123+
outStr.append(
124+
String.format(":First Name: %s%n", this.getFirstName())
125+
);
126+
outStr.append(
127+
String.format(":Address: %s%n", this.getAddress())
128+
);
129+
outStr.append(
130+
String.format(":Date Of Birth: %s%n", this.getDateOfBirth())
131+
);
132+
outStr.append(
133+
String.format(":Restrictions: %s%n", this.getRestrictions())
134+
);
135+
outStr.append(
136+
String.format(":Endorsements: %s%n", this.getEndorsements())
137+
);
138+
outStr.append(
139+
String.format(":Driver License Class: %s%n", this.getDlClass())
140+
);
141+
outStr.append(
142+
String.format(":Sex: %s%n", this.getSex())
143+
);
144+
outStr.append(
145+
String.format(":Height: %s%n", this.getHeight())
146+
);
147+
outStr.append(
148+
String.format(":Weight: %s%n", this.getWeight())
149+
);
150+
outStr.append(
151+
String.format(":Hair Color: %s%n", this.getHairColor())
152+
);
153+
outStr.append(
154+
String.format(":Eye Color: %s%n", this.getEyeColor())
155+
);
156+
outStr.append(
157+
String.format(":Document Discriminator: %s%n", this.getDdNumber())
158+
);
159+
return SummaryHelper.cleanSummary(outStr.toString());
160+
}
161+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.mindee.product.us.driverlicense;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.mindee.parsing.SummaryHelper;
6+
import com.mindee.parsing.standard.PositionField;
7+
import lombok.EqualsAndHashCode;
8+
import lombok.Getter;
9+
10+
/**
11+
* Page data for Driver License, API version 1.
12+
*/
13+
@Getter
14+
@EqualsAndHashCode(callSuper = true)
15+
@JsonIgnoreProperties(ignoreUnknown = true)
16+
public class DriverLicenseV1Page extends DriverLicenseV1Document {
17+
18+
/**
19+
* Has a photo of the US driver license holder
20+
*/
21+
@JsonProperty("photo")
22+
private PositionField photo;
23+
/**
24+
* Has a signature of the US driver license holder
25+
*/
26+
@JsonProperty("signature")
27+
private PositionField signature;
28+
29+
@Override
30+
public String toString() {
31+
StringBuilder outStr = new StringBuilder();
32+
outStr.append(
33+
String.format(":Photo: %s%n", this.getPhoto())
34+
);
35+
outStr.append(
36+
String.format(":Signature: %s%n", this.getSignature())
37+
);
38+
outStr.append(super.toString());
39+
return SummaryHelper.cleanSummary(outStr.toString());
40+
}
41+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.mindee.product.us.driverlicense;
2+
3+
import com.fasterxml.jackson.databind.JavaType;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import com.mindee.parsing.common.Document;
6+
import com.mindee.parsing.common.Page;
7+
import com.mindee.parsing.common.PredictResponse;
8+
import org.junit.jupiter.api.Assertions;
9+
import org.junit.jupiter.api.Test;
10+
import java.io.File;
11+
import java.io.IOException;
12+
import java.nio.file.Files;
13+
import java.nio.file.Paths;
14+
import java.util.List;
15+
16+
/**
17+
* Unit tests for DriverLicenseV1.
18+
*/
19+
public class DriverLicenseV1Test {
20+
21+
protected PredictResponse<DriverLicenseV1> getPrediction() throws IOException {
22+
ObjectMapper objectMapper = new ObjectMapper();
23+
objectMapper.findAndRegisterModules();
24+
25+
JavaType type = objectMapper.getTypeFactory().constructParametricType(
26+
PredictResponse.class,
27+
DriverLicenseV1.class
28+
);
29+
return objectMapper.readValue(
30+
new File("src/test/resources/us/driver_license/response_v1/complete.json"),
31+
type
32+
);
33+
}
34+
35+
@Test
36+
void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException {
37+
PredictResponse<DriverLicenseV1> prediction = getPrediction();
38+
Document<DriverLicenseV1> doc = prediction.getDocument();
39+
String[] actualLines = doc.toString().split(System.lineSeparator());
40+
List<String> expectedLines = Files.readAllLines(
41+
Paths.get("src/test/resources/us/driver_license/response_v1/summary_full.rst")
42+
);
43+
String expectedSummary = String.join(String.format("%n"), expectedLines);
44+
String actualSummary = String.join(String.format("%n"), actualLines);
45+
46+
Assertions.assertEquals(expectedSummary, actualSummary);
47+
}
48+
49+
@Test
50+
void whenCompleteDeserialized_mustHaveValidPage0Summary() throws IOException {
51+
PredictResponse<DriverLicenseV1> prediction = getPrediction();
52+
Page<DriverLicenseV1Page> page = prediction.getDocument().getInference().getPages().get(0);
53+
String[] actualLines = page.toString().split(System.lineSeparator());
54+
List<String> expectedLines = Files.readAllLines(
55+
Paths.get("src/test/resources/us/driver_license/response_v1/summary_page0.rst")
56+
);
57+
String expectedSummary = String.join(String.format("%n"), expectedLines);
58+
String actualSummary = String.join(String.format("%n"), actualLines);
59+
60+
Assertions.assertEquals(expectedSummary, actualSummary);
61+
}
62+
}

0 commit comments

Comments
 (0)