Skip to content

Commit 1515d5d

Browse files
committed
✨ add ocr demo product
1 parent 72b4fce commit 1515d5d

File tree

5 files changed

+143
-1
lines changed

5 files changed

+143
-1
lines changed

src/main/java/com/mindee/CommandLineInterface.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.mindee.product.invoice.InvoiceV4;
1414
import com.mindee.product.invoicesplitter.InvoiceSplitterV1;
1515
import com.mindee.product.multireceiptsdetector.MultiReceiptsDetectorV1;
16+
import com.mindee.product.ocrdemo.OcrDemoV1;
1617
import com.mindee.product.passport.PassportV1;
1718
import com.mindee.product.receipt.ReceiptV4;
1819
import com.mindee.product.receiptsitemsclassifier.ReceiptsItemsClassifierV1;
@@ -98,7 +99,15 @@ void receiptMethod(
9899
System.out.println(standardProductOutput(ReceiptV4.class, file));
99100
}
100101

101-
@Command(name = "multi-receipt-detector", description = "Parse using Multi Receipts Detector")
102+
@Command(name = "receipts-items-classifier", description = "Parse using Receipts Items Classifier")
103+
void receiptsItemsClassifierMethod(
104+
@Parameters(index = "0", paramLabel = "<path>", scope = ScopeType.LOCAL)
105+
File file
106+
) throws IOException, InterruptedException {
107+
System.out.println(standardProductAsyncOutput(ReceiptsItemsClassifierV1.class, file));
108+
}
109+
110+
@Command(name = "multi-receipt-detector", description = "Invokes the Multi Receipts Detector API")
102111
void multiReceiptDetectorMethod(
103112
@Parameters(index = "0", paramLabel = "<path>", scope = ScopeType.LOCAL)
104113
File file
@@ -130,6 +139,14 @@ void internationalIdMethod(
130139
System.out.println(standardProductAsyncOutput(InternationalIdV2.class, file));
131140
}
132141

142+
@Command(name = "ocr", description = "Invokes the OCR API (demo)")
143+
void ocrMethod(
144+
@Parameters(index = "0", paramLabel = "<path>", scope = ScopeType.LOCAL)
145+
File file
146+
) throws IOException {
147+
System.out.println(standardProductOutput(OcrDemoV1.class, file));
148+
}
149+
133150
@Command(name = "custom", description = "Invokes a Custom API")
134151
void customMethod(
135152
@Option(
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.mindee.product.ocrdemo;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.mindee.http.EndpointInfo;
5+
import com.mindee.parsing.common.Inference;
6+
import lombok.Getter;
7+
8+
/**
9+
* The definition for OCR Demo, API version 1.
10+
*/
11+
@Getter
12+
@JsonIgnoreProperties(ignoreUnknown = true)
13+
@EndpointInfo(endpointName = "ocr_demo", version = "1")
14+
public class OcrDemoV1
15+
extends Inference<OcrDemoV1Page, OcrDemoV1Document> {
16+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.mindee.product.ocrdemo;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.mindee.parsing.common.Prediction;
5+
import lombok.EqualsAndHashCode;
6+
import lombok.Getter;
7+
8+
/**
9+
* Document data for OCR Demo, API version 1.
10+
*/
11+
@Getter
12+
@EqualsAndHashCode(callSuper = false)
13+
@JsonIgnoreProperties(ignoreUnknown = true)
14+
public class OcrDemoV1Document extends Prediction {
15+
16+
17+
@Override
18+
public boolean isEmpty() {
19+
return false;
20+
}
21+
22+
@Override
23+
public String toString() {
24+
return "";
25+
}
26+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.mindee.product.ocrdemo;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.mindee.parsing.SummaryHelper;
6+
import com.mindee.parsing.standard.BaseField;
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
import lombok.Getter;
10+
11+
/**
12+
* Full text separated by ' ' for words and '\n' for lines
13+
*/
14+
@Getter
15+
@JsonIgnoreProperties(ignoreUnknown = true)
16+
public class OcrDemoV1Ocr extends BaseField {
17+
18+
/**
19+
* The ocr full text.
20+
*/
21+
@JsonProperty("ocr_full_text")
22+
String ocrFullText;
23+
24+
/**
25+
* Output the object in a format suitable for inclusion in an rST field list.
26+
*/
27+
public String toFieldList() {
28+
Map<String, String> printable = this.printableValues();
29+
return String.format(" :OCR Full Text: %s%n", printable.get("ocrFullText"));
30+
}
31+
32+
@Override
33+
public String toString() {
34+
Map<String, String> printable = this.printableValues();
35+
return String.format("OCR Full Text: %s", printable.get("ocrFullText"));
36+
}
37+
38+
private Map<String, String> printableValues() {
39+
Map<String, String> printable = new HashMap<>();
40+
41+
printable.put("ocrFullText", SummaryHelper.formatString(this.ocrFullText));
42+
return printable;
43+
}
44+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.mindee.product.ocrdemo;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.mindee.parsing.SummaryHelper;
6+
import lombok.EqualsAndHashCode;
7+
import lombok.Getter;
8+
9+
/**
10+
* Page data for OCR Demo, API version 1.
11+
*/
12+
@Getter
13+
@EqualsAndHashCode(callSuper = true)
14+
@JsonIgnoreProperties(ignoreUnknown = true)
15+
public class OcrDemoV1Page extends OcrDemoV1Document {
16+
17+
/**
18+
* Full text separated by ' ' for words and '\n' for lines
19+
*/
20+
@JsonProperty("ocr")
21+
private OcrDemoV1Ocr ocr;
22+
23+
@Override
24+
public boolean isEmpty() {
25+
return (
26+
this.ocr == null
27+
);
28+
}
29+
30+
@Override
31+
public String toString() {
32+
StringBuilder outStr = new StringBuilder();
33+
outStr.append(
34+
String.format(":OCR:%n%s", this.getOcr().toFieldList())
35+
);
36+
outStr.append(super.toString());
37+
return SummaryHelper.cleanSummary(outStr.toString());
38+
}
39+
}

0 commit comments

Comments
 (0)