Skip to content

Commit fd83c5a

Browse files
authored
Merge pull request #243 from rosette-api/RLPNC-7547-error-list
RLPNC-7547:Make optional error string a list of strings for record similarity
2 parents 4187c67 + 2efa83f commit fd83c5a

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

json/src/main/java/com/basistech/rosette/apimodel/jackson/recordsimilaritydeserializers/RecordSimilarityDeserializerUtilities.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ public static RecordSimilarityResult parseResult(JsonNode node, JsonParser jsonP
5959
final Map<String, RecordSimilarityField> right = node.get("right") != null
6060
? parseRecordForResponse(node.get("right"), jsonParser)
6161
: null;
62-
final String error = Optional.ofNullable(node.get("error")).map(JsonNode::asText).orElse(null);
62+
63+
List<String> errorList = Optional.ofNullable(node.get("error"))
64+
.map(jsonNode -> StreamSupport.stream(jsonNode.spliterator(), false)
65+
.map(JsonNode::asText)
66+
.collect(Collectors.toList()))
67+
.orElse(null);
6368
List<String> info = Optional.ofNullable(node.get("info"))
6469
.map(jsonNode -> StreamSupport.stream(jsonNode.spliterator(), false)
6570
.map(JsonNode::asText)
@@ -70,7 +75,7 @@ public static RecordSimilarityResult parseResult(JsonNode node, JsonParser jsonP
7075
.left(left)
7176
.right(right)
7277
.explainInfo(explainInfo)
73-
.error(error)
78+
.error(errorList)
7479
.info(info)
7580
.build();
7681
}

json/src/test/java/com/basistech/rosette/apimodel/recordsimilarity/RecordSimilarityResponseTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.fasterxml.jackson.databind.SerializationFeature;
3030
import org.junit.jupiter.api.Test;
3131

32+
import java.util.Arrays;
3233
import java.util.List;
3334
import java.util.Map;
3435

@@ -37,8 +38,7 @@
3738
public class RecordSimilarityResponseTest {
3839

3940
private static final ObjectMapper MAPPER = ApiModelMixinModule.setupObjectMapper(new ObjectMapper());
40-
41-
private static final String EXPECTED_JSON = "{\"info\":[\"Field threshold not found in properties! Defaulting to 0.0\",\"Field weight not found in fields! Defaulting to 1.0 for all entries\"],\"results\":[{\"explainInfo\":{\"leftOnlyFields\":[\"addr\"],\"scoredFields\":{\"dob\":{\"calculatedWeight\":0.2857142857142857,\"finalScore\":0.74,\"rawScore\":0.8,\"weight\":0.5},\"primaryName\":{\"calculatedWeight\":0.7142857142857143,\"details\":\"any details\",\"finalScore\":0.85,\"rawScore\":0.99,\"weight\":0.5}}},\"left\":{\"addr\":{\"houseNumber\":\"123\",\"road\":\"Roadlane Ave\"},\"dob\":{\"date\":\"1993-04-16\"},\"primaryName\":{\"entityType\":\"PERSON\",\"language\":\"eng\",\"languageOfOrigin\":\"eng\",\"script\":\"Latn\",\"text\":\"Ethan R\"}},\"right\":{\"dob\":\"1993-04-16\",\"primaryName\":{\"text\":\"Seth R\"}},\"score\":0.87},{\"error\":\"Field foo not found in field mapping\",\"info\":[\"Some info message\",\"Some other info message\"],\"left\":{\"addr\":{\"houseNumber\":\"123\",\"road\":\"Roadlane Ave\"},\"dob\":{\"date\":\"1993-04-16\"},\"primaryName\":{\"entityType\":\"PERSON\",\"language\":\"eng\",\"languageOfOrigin\":\"eng\",\"script\":\"Latn\",\"text\":\"Ethan R\"}},\"right\":{\"dob\":\"1993-04-16\",\"primaryName\":{\"text\":\"Seth R\"}}}]}";
41+
private static final String EXPECTED_JSON = "{\"info\":[\"Field threshold not found in properties! Defaulting to 0.0\",\"Field weight not found in fields! Defaulting to 1.0 for all entries\"],\"results\":[{\"explainInfo\":{\"leftOnlyFields\":[\"addr\"],\"scoredFields\":{\"dob\":{\"calculatedWeight\":0.2857142857142857,\"finalScore\":0.74,\"rawScore\":0.8,\"weight\":0.5},\"primaryName\":{\"calculatedWeight\":0.7142857142857143,\"details\":\"any details\",\"finalScore\":0.85,\"rawScore\":0.99,\"weight\":0.5}}},\"left\":{\"addr\":{\"houseNumber\":\"123\",\"road\":\"Roadlane Ave\"},\"dob\":{\"date\":\"1993-04-16\"},\"primaryName\":{\"entityType\":\"PERSON\",\"language\":\"eng\",\"languageOfOrigin\":\"eng\",\"script\":\"Latn\",\"text\":\"Ethan R\"}},\"right\":{\"dob\":\"1993-04-16\",\"primaryName\":{\"text\":\"Seth R\"}},\"score\":0.87},{\"error\":[\"Field foo not found in field mapping\"],\"info\":[\"Some info message\",\"Some other info message\"],\"left\":{\"addr\":{\"houseNumber\":\"123\",\"road\":\"Roadlane Ave\"},\"dob\":{\"date\":\"1993-04-16\"},\"primaryName\":{\"entityType\":\"PERSON\",\"language\":\"eng\",\"languageOfOrigin\":\"eng\",\"script\":\"Latn\",\"text\":\"Ethan R\"}},\"right\":{\"dob\":\"1993-04-16\",\"primaryName\":{\"text\":\"Seth R\"}}}]}";
4242

4343
private static final RecordSimilarityResponse EXPECTED_RESPONSE;
4444

@@ -106,7 +106,7 @@ public class RecordSimilarityResponseTest {
106106
"dob", DateField.UnfieldedDate.builder()
107107
.date("1993-04-16")
108108
.build()))
109-
.error("Field foo not found in field mapping")
109+
.error(Arrays.asList("Field foo not found in field mapping"))
110110
.info(List.of("Some info message", "Some other info message"))
111111
.build()))
112112
.info(List.of(
@@ -122,6 +122,7 @@ public class RecordSimilarityResponseTest {
122122

123123
@Test
124124
public void testDeserialization() throws JsonProcessingException {
125+
// For testing, force ordering
125126
MAPPER.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
126127
MAPPER.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
127128
final RecordSimilarityResponse response = MAPPER.readValue(EXPECTED_JSON, RecordSimilarityResponse.class);

model/src/main/java/com/basistech/rosette/apimodel/recordsimilarity/RecordSimilarityResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ public class RecordSimilarityResult {
3333
Map<String, RecordSimilarityField> left;
3434
Map<String, RecordSimilarityField> right;
3535
RecordSimilarityExplainInfo explainInfo;
36+
List<String> error;
3637
List<String> info;
37-
String error;
3838
}

0 commit comments

Comments
 (0)