Skip to content

Commit 1fbde68

Browse files
committed
♻️ update raw text structure
1 parent e75425d commit 1fbde68

File tree

10 files changed

+164
-49
lines changed

10 files changed

+164
-49
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ public class Inference {
3535
@JsonProperty("file")
3636
private InferenceFile file;
3737

38+
/**
39+
* Active options for the inference.
40+
*/
41+
@JsonProperty("active_options")
42+
private InferenceActiveOptions activeOptions;
43+
3844
/**
3945
* Model result values.
4046
*/
@@ -47,12 +53,12 @@ public String toString() {
4753
joiner
4854
.add("Inference")
4955
.add("#########")
50-
.add("Model")
51-
.add("=====")
52-
.add(":ID: " + (model != null ? model.getId() : ""))
56+
.add(model.toString())
5357
.add("")
5458
.add(file.toString())
5559
.add("")
60+
.add(activeOptions.toString())
61+
.add("")
5662
.add(result != null ? result.toString() : "");
5763
return joiner.toString().trim() + "\n";
5864
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.mindee.parsing.v2;
2+
3+
import static com.mindee.parsing.SummaryHelper.formatForDisplay;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import java.util.StringJoiner;
7+
8+
/**
9+
* Option response for V2 API inference.
10+
*/
11+
public final class InferenceActiveOptions {
12+
13+
@JsonProperty("rag")
14+
private boolean rag;
15+
16+
@JsonProperty("raw_text")
17+
private boolean rawText;
18+
19+
@JsonProperty("polygon")
20+
private boolean polygon;
21+
22+
@JsonProperty("confidence")
23+
private boolean confidence;
24+
25+
/**
26+
* Whether the RAG feature was activated.
27+
*/
28+
public boolean getRag() {
29+
return rag;
30+
}
31+
32+
/**
33+
* Whether the Raw Text feature was activated.
34+
*/
35+
public boolean getRawText() {
36+
return rawText;
37+
}
38+
39+
/**
40+
* Whether the polygon feature was activated.
41+
*/
42+
public boolean getPolygon() {
43+
return polygon;
44+
}
45+
46+
/**
47+
* Whether the confidence feature was activated.
48+
*/
49+
public boolean getConfidence() {
50+
return confidence;
51+
}
52+
53+
@Override
54+
public String toString() {
55+
StringJoiner joiner = new StringJoiner("\n");
56+
return joiner
57+
.add("Active Options")
58+
.add("==============")
59+
.add(":Raw Text: " + formatForDisplay(rawText, 5))
60+
.add(":Polygon: " + formatForDisplay(polygon, 5))
61+
.add(":Confidence: " + formatForDisplay(confidence, 5))
62+
.add(":RAG: " + formatForDisplay(rag, 5))
63+
.toString();
64+
}
65+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
44
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import java.util.StringJoiner;
56
import lombok.AllArgsConstructor;
67
import lombok.EqualsAndHashCode;
78
import lombok.Getter;
@@ -22,4 +23,13 @@ public class InferenceModel {
2223
*/
2324
@JsonProperty("id")
2425
private String id;
26+
27+
public String toString() {
28+
StringJoiner joiner = new StringJoiner("\n");
29+
return joiner
30+
.add("Model")
31+
.add("=====")
32+
.add(":ID: " + id)
33+
.toString();
34+
}
2535
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,16 @@ public final class InferenceResult {
2828
/**
2929
* Options.
3030
*/
31-
@JsonProperty("options")
32-
private InferenceResultOptions options;
31+
@JsonProperty("raw_text")
32+
private RawText rawText;
3333

3434
@Override
3535
public String toString() {
3636
StringJoiner joiner = new StringJoiner("\n");
3737
joiner.add("Fields")
3838
.add("======");
3939
joiner.add(fields.toString());
40-
if (this.getOptions() != null) {
41-
joiner.add("Options")
42-
.add("=======")
43-
.add(this.getOptions().toString());
44-
}
40+
4541
return joiner.toString();
4642
}
4743
}

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

Lines changed: 0 additions & 15 deletions
This file was deleted.

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
44
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import java.util.List;
6+
import java.util.StringJoiner;
57
import lombok.AllArgsConstructor;
68
import lombok.Getter;
79
import lombok.NoArgsConstructor;
@@ -17,12 +19,19 @@ public class RawText {
1719
/*
1820
* Page Number the text was found on.
1921
*/
20-
@JsonProperty("page")
21-
private Integer page;
22+
@JsonProperty("pages")
23+
private List<RawTextPage> pages;
2224

23-
/*
24-
* Content of the raw text.
25-
*/
26-
@JsonProperty("content")
27-
private String content;
25+
@Override
26+
public String toString() {
27+
if (pages == null || pages.isEmpty()) {
28+
return "";
29+
}
30+
StringJoiner joiner = new StringJoiner("\n\n");
31+
for (RawTextPage page : pages) {
32+
joiner.add(page.toString());
33+
}
34+
return joiner.toString();
35+
36+
}
2837
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.mindee.parsing.v2;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Getter;
7+
import lombok.NoArgsConstructor;
8+
9+
/**
10+
* Raw text extracted from the page.
11+
*/
12+
@Getter
13+
@JsonIgnoreProperties(ignoreUnknown = true)
14+
@AllArgsConstructor
15+
@NoArgsConstructor
16+
public class RawTextPage {
17+
/**
18+
* Page content as a single string.
19+
*/
20+
@JsonProperty("content")
21+
private String content;
22+
23+
/**
24+
* Page contents as a string.
25+
*/
26+
@Override
27+
public String toString() {
28+
if (content == null) {
29+
return "";
30+
}
31+
return content;
32+
}
33+
}

src/test/java/com/mindee/MindeeClientV2IT.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.mindee.http.MindeeHttpExceptionV2;
44
import com.mindee.input.LocalInputSource;
55
import com.mindee.input.URLInputSource;
6+
import com.mindee.parsing.v2.InferenceActiveOptions;
67
import com.mindee.parsing.v2.InferenceResponse;
78
import java.io.File;
89
import java.io.IOException;
@@ -55,7 +56,13 @@ void parseFile_emptyMultiPage_mustSucceed() throws IOException, InterruptedExcep
5556
assertEquals(modelId, response.getInference().getModel().getId());
5657

5758
assertNotNull(response.getInference().getResult());
58-
assertNull(response.getInference().getResult().getOptions());
59+
60+
InferenceActiveOptions activeOptions = response.getInference().getActiveOptions();
61+
assertNotNull(activeOptions);
62+
assertFalse(activeOptions.getRag());
63+
assertFalse(activeOptions.getRawText());
64+
assertFalse(activeOptions.getPolygon());
65+
assertFalse(activeOptions.getConfidence());
5966
}
6067

6168
@Test

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,22 @@ class CompletePrediction {
9999
@DisplayName("every exposed property must be valid and consistent")
100100
void asyncPredict_whenComplete_mustExposeAllProperties() throws IOException {
101101
InferenceResponse response = loadFromResource("v2/products/financial_document/complete.json");
102-
Inference inf = response.getInference();
103-
assertNotNull(inf, "Inference must not be null");
104-
assertEquals("12345678-1234-1234-1234-123456789abc", inf.getId(), "Inference ID mismatch");
102+
Inference inference = response.getInference();
103+
assertNotNull(inference, "Inference must not be null");
104+
assertEquals("12345678-1234-1234-1234-123456789abc", inference.getId(), "Inference ID mismatch");
105105

106-
InferenceModel model = inf.getModel();
106+
InferenceModel model = inference.getModel();
107107
assertNotNull(model, "Model must not be null");
108108
assertEquals("12345678-1234-1234-1234-123456789abc", model.getId(), "Model ID mismatch");
109109

110-
InferenceFile file = inf.getFile();
110+
InferenceFile file = inference.getFile();
111111
assertNotNull(file, "File must not be null");
112112
assertEquals("complete.jpg", file.getName(), "File name mismatch");
113113
assertEquals(1, file.getPageCount(), "Page count mismatch");
114114
assertEquals("image/jpeg", file.getMimeType(), "MIME type mismatch");
115115
assertNull(file.getAlias(), "File alias must be null for this payload");
116116

117-
InferenceFields fields = inf.getResult().getFields();
117+
InferenceFields fields = inference.getResult().getFields();
118118
assertEquals(21, fields.size(), "Expected 21 fields in the payload");
119119

120120
SimpleField date = fields.get("date").getSimpleField();
@@ -146,7 +146,8 @@ void asyncPredict_whenComplete_mustExposeAllProperties() throws IOException {
146146
SimpleField city = customerAddr.getFields().get("city").getSimpleField();
147147
assertEquals("New York", city.getValue(), "City mismatch");
148148

149-
assertNull(inf.getResult().getOptions(), "Options must be null");
149+
InferenceActiveOptions activeOptions = inference.getActiveOptions();
150+
assertNotNull(activeOptions);
150151
}
151152
}
152153

@@ -451,17 +452,20 @@ class RawTexts {
451452
@DisplayName("raw texts option must be parsed and exposed")
452453
void rawTexts_mustBeAccessible() throws IOException {
453454
InferenceResponse resp = loadFromResource("v2/inference/raw_texts.json");
454-
Inference inf = resp.getInference();
455-
assertNotNull(inf);
455+
Inference inference = resp.getInference();
456+
assertNotNull(inference);
456457

457-
InferenceResultOptions opts = inf.getResult().getOptions();
458-
assertNotNull(opts, "Options should not be null");
458+
InferenceActiveOptions activeOptions = inference.getActiveOptions();
459+
assertNotNull(activeOptions);
460+
assertFalse(activeOptions.getRag());
461+
assertTrue(activeOptions.getRawText());
462+
assertFalse(activeOptions.getPolygon());
463+
assertFalse(activeOptions.getConfidence());
459464

460-
List<RawText> rawTexts = opts.getRawTexts();
461-
assertEquals(2, rawTexts.size());
465+
RawText rawText = inference.getResult().getRawText();
466+
assertEquals(2, rawText.getPages().size());
462467

463-
RawText first = rawTexts.get(0);
464-
assertEquals(0, first.getPage());
468+
RawTextPage first = rawText.getPages().get(0);
465469
assertEquals("This is the raw text of the first page...", first.getContent());
466470
}
467471
}

0 commit comments

Comments
 (0)