Skip to content

Commit 6200848

Browse files
committed
♻️ update raw text structure
1 parent bd70e08 commit 6200848

File tree

10 files changed

+117
-40
lines changed

10 files changed

+117
-40
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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
import lombok.Getter;
8+
9+
/**
10+
* Option response for V2 API inference.
11+
*/
12+
@Getter
13+
public final class InferenceActiveOptions {
14+
15+
@JsonProperty("rag")
16+
private boolean rag;
17+
18+
@JsonProperty("raw_text")
19+
private boolean rawText;
20+
21+
@JsonProperty("polygon")
22+
private boolean polygon;
23+
24+
@JsonProperty("confidence")
25+
private boolean confidence;
26+
27+
@Override
28+
public String toString() {
29+
StringJoiner joiner = new StringJoiner("\n");
30+
return joiner
31+
.add("Active Options")
32+
.add("==============")
33+
.add(":Raw Text: " + formatForDisplay(rawText, 5))
34+
.add(":Polygon: " + formatForDisplay(polygon, 5))
35+
.add(":Confidence: " + formatForDisplay(confidence, 5))
36+
.add(":RAG: " + formatForDisplay(rag, 5))
37+
.toString();
38+
}
39+
}

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void parseFile_emptyMultiPage_mustSucceed() throws IOException, InterruptedExcep
5555
assertEquals(modelId, response.getInference().getModel().getId());
5656

5757
assertNotNull(response.getInference().getResult());
58-
assertNull(response.getInference().getResult().getOptions());
58+
assertNotNull(response.getInference().getActiveOptions());
5959
}
6060

6161
@Test

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ 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+
assertNotNull(inf.getActiveOptions(), "Options must be null");
150150
}
151151
}
152152

@@ -454,14 +454,13 @@ void rawTexts_mustBeAccessible() throws IOException {
454454
Inference inf = resp.getInference();
455455
assertNotNull(inf);
456456

457-
InferenceResultOptions opts = inf.getResult().getOptions();
457+
InferenceActiveOptions opts = inf.getActiveOptions();
458458
assertNotNull(opts, "Options should not be null");
459459

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

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

0 commit comments

Comments
 (0)