Skip to content

Commit 30192fe

Browse files
✨ add text context return option (#284)
1 parent 7ac72dc commit 30192fe

File tree

5 files changed

+94
-4
lines changed

5 files changed

+94
-4
lines changed

src/main/java/com/mindee/parsing/v2/InferenceActiveOptions.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public final class InferenceActiveOptions {
2727
@JsonProperty("confidence")
2828
private boolean confidence;
2929

30+
@JsonProperty("text_context")
31+
private boolean textContext;
32+
3033
/**
3134
* Data schema options provided for the inference.
3235
*/
@@ -62,6 +65,11 @@ public boolean getConfidence() {
6265
return confidence;
6366
}
6467

68+
/**
69+
* Whether the text context feature was activated.
70+
*/
71+
public boolean getTextContext() { return textContext; }
72+
6573
@Override
6674
public String toString() {
6775
StringJoiner joiner = new StringJoiner("\n");

src/test/java/com/mindee/input/LocalResponseTest.java renamed to src/test/java/com/mindee/input/LocalResponseV1Test.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
import java.io.IOException;
77
import java.nio.file.Files;
88
import java.nio.file.Path;
9-
import java.nio.file.Paths;
109

1110
import static com.mindee.TestingUtilities.getV1ResourcePath;
12-
import static com.mindee.TestingUtilities.getV1ResourcePathString;
1311

1412

15-
public class LocalResponseTest {
13+
public class LocalResponseV1Test {
1614
/**
1715
* Fake secret key.
1816
*/
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.mindee.input;
2+
3+
import com.mindee.parsing.v2.InferenceResponse;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.io.File;
8+
import java.io.IOException;
9+
import java.nio.file.Files;
10+
import java.nio.file.Path;
11+
12+
import static com.mindee.TestingUtilities.getV2ResourcePath;
13+
14+
15+
public class LocalResponseV2Test {
16+
/**
17+
* Fake secret key.
18+
*/
19+
String secretKey = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH";
20+
21+
/**
22+
* Real signature using fake secret key.
23+
*/
24+
String signature = "b82a515c832fd2c4f4ce3a7e6f53c12e8d10e19223f6cf0e3a9809a7a3da26be";
25+
26+
/**
27+
* File which the signature applies to.
28+
*/
29+
Path filePath = getV2ResourcePath("inference/standard_field_types.json");
30+
31+
protected void assertLocalResponse(LocalResponse localResponse) {
32+
Assertions.assertNotNull(localResponse.getFile());
33+
Assertions.assertFalse(localResponse.isValidHmacSignature(
34+
this.secretKey, "invalid signature is invalid")
35+
);
36+
Assertions.assertEquals(this.signature, localResponse.getHmacSignature(this.secretKey));
37+
Assertions.assertTrue(localResponse.isValidHmacSignature(this.secretKey, this.signature));
38+
InferenceResponse response = localResponse.deserializeResponse(InferenceResponse.class);
39+
Assertions.assertNotNull(response);
40+
Assertions.assertNotNull(response.getInference());
41+
}
42+
43+
@Test
44+
void loadDocument_withFile_mustReturnValidLocalResponse() throws IOException {
45+
LocalResponse localResponse = new LocalResponse(new File(this.filePath.toString()));
46+
assertLocalResponse(localResponse);
47+
}
48+
49+
@Test
50+
void loadDocument_withString_mustReturnValidLocalResponse() {
51+
LocalResponse localResponse = new LocalResponse("{'some': 'json', 'with': 'data'}");
52+
Assertions.assertNotNull(localResponse.getFile());
53+
Assertions.assertFalse(localResponse.isValidHmacSignature(
54+
this.secretKey, "invalid signature is invalid")
55+
);
56+
}
57+
58+
@Test
59+
void loadDocument_withInputStream_mustReturnValidLocalResponse() throws IOException {
60+
LocalResponse localResponse = new LocalResponse(
61+
Files.newInputStream(this.filePath)
62+
);
63+
assertLocalResponse(localResponse);
64+
}
65+
}

src/test/java/com/mindee/parsing/v2/InferenceTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ void asyncPredict_whenComplete_mustExposeAllProperties() throws IOException {
148148

149149
InferenceActiveOptions activeOptions = inference.getActiveOptions();
150150
assertNotNull(activeOptions);
151+
assertFalse(activeOptions.getConfidence());
152+
assertFalse(activeOptions.getRag());
153+
assertFalse(activeOptions.getRawText());
154+
assertFalse(activeOptions.getTextContext());
155+
assertFalse(activeOptions.getPolygon());
151156
}
152157
}
153158

@@ -466,6 +471,7 @@ void rawTexts_mustBeAccessible() throws IOException {
466471
assertTrue(activeOptions.getRawText());
467472
assertFalse(activeOptions.getPolygon());
468473
assertFalse(activeOptions.getConfidence());
474+
assertFalse(activeOptions.getTextContext());
469475
assertFalse(activeOptions.getDataSchema().getOverride());
470476

471477
assertNull(inference.getResult().getRag());
@@ -525,4 +531,17 @@ void rstDisplay_mustBeAccessible() throws IOException {
525531
assertEquals(rstRef, resp.getInference().toString());
526532
}
527533
}
534+
535+
@Nested
536+
@DisplayName("Text Context Return")
537+
class TextContextTest {
538+
@Test
539+
@DisplayName("should be present and true when enabled")
540+
void textContext_mustBePresentAndTrue() throws IOException {
541+
InferenceResponse resp = loadInference("inference/text_context_enabled.json");
542+
Inference inf = resp.getInference();
543+
assertNotNull(inf);
544+
assertTrue(inf.getActiveOptions().getTextContext());
545+
}
546+
}
528547
}

0 commit comments

Comments
 (0)