Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/v1/parsing/common/ocrPage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
compareOnX,
compareOnY,
getCentroid,
isPointInPolygonY,
} from "@/geometry/index.js";
import { Word } from "@/v1/parsing/standard/index.js";
Expand All @@ -16,8 +15,8 @@ export class OcrPage {
constructor(rawPrediction: StringDict) {
const allWords: Word[] = [];
if (rawPrediction["all_words"]) {
rawPrediction["all_words"].forEach((word: Word) => {
allWords.push(word);
rawPrediction["all_words"].forEach((word: StringDict) => {
allWords.push(new Word(word));
});
}
this.allWords = allWords.sort((word1, word2) =>
Expand All @@ -27,11 +26,11 @@ export class OcrPage {

#areWordsOnSameLine(currentWord: Word, nextWord: Word) {
const currentInNext = isPointInPolygonY(
getCentroid(currentWord.polygon),
currentWord.polygon.getCentroid(),
nextWord.polygon
);
const nextInCurrent = isPointInPolygonY(
getCentroid(nextWord.polygon),
nextWord.polygon.getCentroid(),
currentWord.polygon
);
return nextInCurrent || currentInNext;
Expand Down
2 changes: 1 addition & 1 deletion src/v1/parsing/standard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export { Taxes, TaxField } from "./tax.js";
export { StringField } from "./text.js";
export { PaymentDetailsField } from "./paymentDetails.js";
export { PositionField } from "./position.js";
export type { Word } from "./word.js";
export { Word } from "./word.js";
13 changes: 10 additions & 3 deletions src/v1/parsing/standard/word.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import * as geometry from "@/geometry/index.js";
import { Polygon } from "@/geometry/index.js";
import { StringDict } from "@/parsing/index.js";

export type Word = {
export class Word {
/**
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: geometry.Polygon;
polygon: Polygon;
text: string;
confidence: number;

constructor(rawPrediction: StringDict) {
this.polygon = new Polygon(...rawPrediction["polygon"]);
this.text = rawPrediction["text"];
this.confidence = rawPrediction["confidence"];
}
};