Skip to content

Commit 54ad973

Browse files
meganlevinMeganfhasanajNorbert Nagyavarga-precognox
authored
RLPNC-7384: Add Request Object in Java Bindings (#215)
RLPNC-7384: support RecordSimilarity --------- Co-authored-by: Megan <[email protected]> Co-authored-by: Fiona Hasanaj <[email protected]> Co-authored-by: Norbert Nagy <[email protected]> Co-authored-by: Akos Varga <[email protected]> Co-authored-by: jsquatrito <[email protected]> Co-authored-by: norbert nagy <[email protected]> Co-authored-by: Ethan Roseman <[email protected]> Co-authored-by: Ian Redpath <[email protected]>
1 parent 696d199 commit 54ad973

File tree

36 files changed

+1359
-1
lines changed

36 files changed

+1359
-1
lines changed

api/src/test/java/com/basistech/rosette/api/RosetteAPITest.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
import com.basistech.rosette.apimodel.SentimentResponse;
4040
import com.basistech.rosette.apimodel.SyntaxDependenciesResponse;
4141
import com.basistech.rosette.apimodel.jackson.ApiModelMixinModule;
42+
import com.basistech.rosette.apimodel.recordsimilarity.RecordSimilarityRequest;
43+
import com.basistech.rosette.apimodel.recordsimilarity.RecordSimilarityResponse;
44+
4245
import com.fasterxml.jackson.databind.DeserializationFeature;
4346
import com.fasterxml.jackson.databind.ObjectMapper;
4447
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
@@ -212,6 +215,68 @@ private NameSimilarityRequest readValueNameMatcher(String testFilename) throws I
212215
return mapper.readValue(input, NameSimilarityRequest.class);
213216
}
214217

218+
private static Stream<Arguments> testMatchRecordParameters() throws IOException {
219+
return getTestFiles("-record-similarity.json");
220+
}
221+
222+
@ParameterizedTest(name = "testFilename: {0}; statusCode: {2}")
223+
@MethodSource("testMatchRecordParameters")
224+
void testMatchRecord(String testFilename, String responseStr, int statusCode) throws IOException {
225+
setStatusCodeResponse(responseStr, statusCode);
226+
RecordSimilarityRequest request = readValueRecordMatcher(testFilename);
227+
try {
228+
RecordSimilarityResponse response = api.perform(AbstractRosetteAPI.RECORD_SIMILARITY_SERVICE_PATH, request,
229+
RecordSimilarityResponse.class);
230+
verifyRecordMatcher(response, responseStr);
231+
} catch (HttpRosetteAPIException e) {
232+
verifyException(e, responseStr);
233+
}
234+
}
235+
236+
private static Stream<Arguments> testMatchRecordMissingFieldParameters() throws IOException {
237+
return getTestFiles("-record-similarity-missing-field.json");
238+
}
239+
240+
@ParameterizedTest(name = "testFilename: {0}; statusCode: {2}")
241+
@MethodSource("testMatchRecordMissingFieldParameters")
242+
void testMatchRecordMissingField(String testFilename, String responseStr, int statusCode) throws IOException {
243+
setStatusCodeResponse(responseStr, statusCode);
244+
245+
try {
246+
readValueRecordMatcher(testFilename);
247+
fail("Did not throw exception for a field type in request but not in mapping");
248+
} catch (IllegalArgumentException e) {
249+
assertEquals("Unsupported field name: primaryName not found in field mapping", e.getMessage());
250+
}
251+
}
252+
253+
private static Stream<Arguments> testMatchRecordNullFieldParameters() throws IOException {
254+
return getTestFiles("-record-similarity-null-field.json");
255+
}
256+
257+
@ParameterizedTest(name = "testFilename: {0}; statusCode: {2}")
258+
@MethodSource("testMatchRecordNullFieldParameters")
259+
void testMatchRecordNullField(String testFilename, String responseStr, int statusCode) throws IOException {
260+
setStatusCodeResponse(responseStr, statusCode);
261+
262+
try {
263+
readValueRecordMatcher(testFilename);
264+
fail("Did not throw exception for a field with null type");
265+
} catch (IllegalArgumentException e) {
266+
assertEquals("Unspecified field type for: primaryName", e.getMessage());
267+
}
268+
}
269+
270+
private void verifyRecordMatcher(RecordSimilarityResponse response, String responseStr) throws IOException {
271+
RecordSimilarityResponse goldResponse = mapper.readValue(responseStr, RecordSimilarityResponse.class);
272+
assertEquals(goldResponse.getResults(), response.getResults());
273+
}
274+
275+
private RecordSimilarityRequest readValueRecordMatcher(String testFilename) throws IOException {
276+
File input = new File("src/test/mock-data/request", testFilename);
277+
return mapper.readValue(input, RecordSimilarityRequest.class);
278+
}
279+
215280
private static Stream<Arguments> testMatchAddressParameters() throws IOException {
216281
return getTestFiles("-address-similarity.json");
217282
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"fields": {
3+
"homeAddress": {
4+
"type": "rni_address",
5+
"weight": 0.5
6+
},
7+
"dob": {
8+
"type": "rni_date",
9+
"weight": 0.2
10+
},
11+
"dob2": {
12+
"type": "rni_date",
13+
"weight": 0.1
14+
},
15+
"addr": {
16+
"type": "rni_address",
17+
"weight": 0.5
18+
}
19+
},
20+
"properties": {
21+
"threshold": 0.7
22+
},
23+
"records": {
24+
"left": [
25+
{
26+
"primaryName": {
27+
"data": "Ethan R",
28+
"language": "eng",
29+
"entityType": "PERSON"
30+
},
31+
"dob": "1993-04-16",
32+
"dob2": "1993/04/16",
33+
"addr": "123 Roadlane Ave"
34+
},
35+
{
36+
"primaryName": "Evan R",
37+
"dob": "1993-04-16"
38+
}
39+
],
40+
"right": [
41+
{
42+
"primaryName": "Seth R",
43+
"dob": "1993-04-16"
44+
},
45+
{
46+
"primaryName": "Ivan R",
47+
"dob": "1993-04-16",
48+
"dob2": "1993/04/16",
49+
"addr": "123 Roadlane Ave"
50+
}
51+
]
52+
}
53+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"fields": {
3+
"primaryName": {
4+
"type": null,
5+
"weight": 0.5
6+
},
7+
"dob": {
8+
"type": "rni_date",
9+
"weight": 0.2
10+
},
11+
"dob2": {
12+
"type": "rni_date",
13+
"weight": 0.1
14+
},
15+
"addr": {
16+
"type": "rni_address",
17+
"weight": 0.5
18+
}
19+
},
20+
"properties": {
21+
"threshold": 0.7
22+
},
23+
"records": {
24+
"left": [
25+
{
26+
"primaryName": {
27+
"data": "Ethan R",
28+
"language": "eng",
29+
"entityType": "PERSON"
30+
},
31+
"dob": "1993-04-16",
32+
"dob2": "1993/04/16",
33+
"addr": "123 Roadlane Ave"
34+
},
35+
{
36+
"primaryName": "Evan R",
37+
"dob": "1993-04-16"
38+
}
39+
],
40+
"right": [
41+
{
42+
"primaryName": "Seth R",
43+
"dob": "1993-04-16"
44+
},
45+
{
46+
"primaryName": "Ivan R",
47+
"dob": "1993-04-16",
48+
"dob2": "1993/04/16",
49+
"addr": "123 Roadlane Ave"
50+
}
51+
]
52+
}
53+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"fields": {
3+
"primaryName": {
4+
"type": "rni_name",
5+
"weight": 0.5
6+
},
7+
"dob": {
8+
"type": "rni_date",
9+
"weight": 0.2
10+
},
11+
"dob2": {
12+
"type": "rni_date",
13+
"weight": 0.1
14+
},
15+
"addr": {
16+
"type": "rni_address",
17+
"weight": 0.5
18+
}
19+
},
20+
"properties": {
21+
"threshold": 0.7
22+
},
23+
"records": {
24+
"left": [
25+
{
26+
"primaryName": {
27+
"text": "Ethan R",
28+
"language": "eng",
29+
"entityType": "PERSON"
30+
},
31+
"dob": "1993-04-16",
32+
"dob2": "1993/04/16",
33+
"addr": "123 Roadlane Ave"
34+
},
35+
{
36+
"primaryName": {
37+
"text": "Evan R"
38+
},
39+
"dob": "1993-04-16"
40+
}
41+
],
42+
"right": [
43+
{
44+
"primaryName": {
45+
"text": "Seth R"
46+
},
47+
"dob": "1993-04-16"
48+
},
49+
{
50+
"primaryName": {
51+
"text": "Ivan R"
52+
},
53+
"dob": "1993-04-16",
54+
"dob2": "1993/04/16",
55+
"addr": "123 Roadlane Ave"
56+
}
57+
]
58+
}
59+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"code": "badRequestFormat",
3+
"message": "Unsupported field name: primaryName not found in field mapping",
4+
"stack": null
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
400
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"code": "badRequestFormat",
3+
"message": "Unspecified field type for: primaryName",
4+
"stack": null
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
400
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"results": [
3+
{
4+
"fields": {
5+
"primaryName": {
6+
"type": "rni_name",
7+
"weight": 0.5
8+
},
9+
"dob": {
10+
"type": "rni_date",
11+
"weight": 0.2
12+
},
13+
"dob2": {
14+
"type": "rni_date",
15+
"weight": 0.1
16+
},
17+
"addr": {
18+
"type": "rni_address",
19+
"weight": 0.5
20+
}
21+
},
22+
"score": 0.87,
23+
"left": {
24+
"primaryName": "Ethan R",
25+
"dob": "1993-04-16",
26+
"dob2": "1993/04/16",
27+
"addr": "123 Roadlane Ave"
28+
},
29+
"right": {
30+
"primaryName": "Seth R",
31+
"dob": "1993-04-16"
32+
},
33+
"explainInfo": {
34+
"scoredFields": {
35+
"primaryName": {
36+
"rawScore": 0.99,
37+
"calculatedWeight": 0.7142857142857143
38+
},
39+
"dob": {
40+
"rawScore": 0.8,
41+
"calculatedWeight": 0.2857142857142857
42+
}
43+
},
44+
"rightOnlyFields": [
45+
"dob2",
46+
"addr"
47+
]
48+
}
49+
}
50+
]
51+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
200

0 commit comments

Comments
 (0)